HomeAboutArchivesTools & ResourcesSupport me
Hi! 👋 I'm Szymon

I help you become a better software developer.

  • 1.15kFollowers
  • 2.36kSubscribers
  • 110Followers
  • 30.2kReputation

Popular categories

  • Groovy Cookbook28
  • Jenkins Pipeline Cookbook9
  • Programmer's Bookshelf6
  • Micronaut Cookbook4
  • Ratpack Cookbook4
  • Learning Java4
  • jq cookbook3
  • How to3
  • Blog Reports2

Don't miss anything - join my newsletter

Additional materials and updates for subscribers. No spam guaranteed.
Unsubscribe at any time.

Did you like this article?

Spread the !
  • ☕️
  1. e.printstacktrace.blog
  2. Jenkins Pipeline Cookbook

Jenkins Declarative Pipeline with the dynamic agent - how to configure it?

  • September 27, 2020
  • 1 min. read
  • 0 Comments

In some cases, you would like to use Jenkins declarative pipeline with the dynamic agent. For instance, you want to provide a list of available agent nodes as a parameter for the pipeline job. In this blog post, I will explain how you can configure such a behavior in just a few steps.

Jenkins Pipeline agent label from the parameter

Listing 1. Jenkinsfile
pipeline {
    agent {
        label params.AGENT == "any" ? "" : params.AGENT (1)
    }

    parameters {
        choice(name: "AGENT", choices: ["any", "docker", "windows", "linux"]) (2)
    }

    stages {
        stage("Build") {
            steps {
                echo "Hello, World!"
            }
        }
    }
}

There is one thing worth explaining. You can see that in the line , we check if params.AGENT is equal to "any". If this is the case, we put an empty string instead. (An empty string in this case is an equivalent of agent any - source.) Otherwise, Jenkins would search for the node with label "any" instead.

In the line , we define a list of available nodes. When you start the job and choose any from the dropdown, any available node will be used to run the job. If you choose docker, windows, or linux (or any other label you will define in your pipeline), the node with that exact label will be used to run the job. And that’s it.

  • devops
  • jenkins
  • jenkins-pipeline
  • continuous-integration
  • jenkinsfile

jq cookbook

Merging JSON files recursively in the command-line

  • November 5, 2020
  • 1 min. read
  • 0 Comments

Have you ever need to merge two (or more) JSON files and you wondered if you can do it in the command-line? In this blog post, I will show you how you can use jq command-line JSON processor to merge recursively multiple JSON files.

Jenkins Pipeline Cookbook

How to time out Jenkins Pipeline stage and keep the pipeline running?

  • April 16, 2020
  • 1 min. read
  • 0 Comments

The declarative Jenkins Pipeline allows us to define timeout either at the pipeline level or the...

Jenkins Pipeline Cookbook

Building Java and Maven docker images using parallelized Jenkins Pipeline and SDKMAN!

  • November 11, 2019
  • 1 min. read
  • 0 Comments

In the last article, I have shown you how you can build a docker image for Jenkins Pipeline usin...

Jenkins Pipeline Cookbook

5 Common Jenkins Pipeline Mistakes

  • August 24, 2020
  • 1 min. read
  • 0 Comments

Do you know that you can unit test your Jenkins pipeline code? Have you ever used linter to vali...

Any thoughts or ideas?

Let's talk in the comment's section 💬

Want to put a code sample in the comment? Read the Syntax highlighting guide for more information.
Empty
Latest blog posts
  • Merging JSON files recursively in the command-line
  • Jenkins Declarative Pipeline with the dynamic agent - how to configure it?
  • Groovy Ecosystem Usage Report (2020)
  • How to convert JSON to CSV from the command-line?
  • 5 Common Jenkins Pipeline Mistakes
  • How to merge two maps in Groovy?
  • Building stackoverflow-cli with Java 11, Micronaut, Picocli, and GraalVM
  • How to catch curl response in Jenkins Pipeline?
  • Atomic Habits - book review
  • Parsing JSON in command-line with jq: basic filters and functions (part 1)
Trending videos
Using GraalVM native-image with a Groovy script - from 2.1s to 0.013s startup time 🚀

GraalVM native-image compiler uses ahead-of-time compilation to produce a highly optimized standalone executable file that ca...

Jenkins Declarative Pipeline vs Scripted Pipeline - 4 key differences | #jenkinspipeline

Jenkins Pipeline as a code is a new standard for defining continuous integration and delivery pipelines in Jenkins. The scrip...

Useful links
  • Start here
  • About
  • Archives
  • Resources
  • Privacy Policy
  • Merchandise
  • My Kit
  • RSS
  • Support the blog
Popular categories
  • Groovy Cookbook28
  • Jenkins Pipeline Cookbook9
  • Programmer's Bookshelf6
  • Micronaut Cookbook4
  • Ratpack Cookbook4
  • Learning Java4
  • jq cookbook3
  • How to3
  • Blog Reports2
Popular tags
affiliate async benchmark blogging book career cicd continuous-integration curl devops docker git github graalvm gradle grails groovy haskell hexo java java-8 jenkins jenkins-pipeline jenkinsfile jmh jq json junit learning maven metaprogramming micronaut native-image non-blocking progress ratpack reactive-programming reading recursion review rxjava sdkman session split spock stackoverflow string tail-call tail-recursion unit-test
  • Designed by @wololock
  • Created with Hexo
  • Hosted on GitHub
  • Deployed with Circle CI
  • License CC BY-NC-SA 4.0