How can we specify the agent to use to build a job?
- CloudBees Core
- CloudBees Core on modern cloud platforms - Managed Master
- CloudBees Core on modern cloud platforms - Operations Center
- CloudBees Core on traditional platforms - Client Master
- CloudBees Core on traditional platforms - Operations Center
- CloudBees Jenkins Enterprise
- CloudBees Jenkins Enterprise - Managed Master
- CloudBees Jenkins Enterprise - Operations Center
- CloudBees Jenkins Platform - Client Master
- CloudBees Jenkins Platform - Operations Center
- CloudBees Jenkins Distribution
- Jenkins LTS
When you have multiple agent available, whether you are using a classic job type (Freestyle, Maven, etc) or a Pipeline (even Multibranch Pipeline), you can select a specific agent to build your project.
In a classic job type, you will find a Restrict where this project can be run checkbox and text field in the properties of the job:
In a (Multibranch) Pipeline, you can specify this in the parameter of the
The value of both the text field and the
node parameter are the same: it can be the agent name, or a Groovy boolean expression.
Using the agent name, you make the job tied to this specific agent. This can be problematic when the build load grow, your agent becomes less and less available.
The best solution is to use the labels. When you configure your agents, you can put a space-separated list of labels on your agent. Those can be used to describe what the agent can be used for:
npm, etc. It can also describe what the agent is running on:
x64, etc. This will create pools of agents based on the labels. Then, on your job configuration, you can use those label in a Groovy boolean expression to select the correct agent for your job:
- “I need an agent running on linux”:
- “I need an agent running on windows with maven”:
windows && maven
- “I need an agent with a jdk-8 and running either on windows x32 or linux x64”:
jdk-8 && ((windows && x32) || (linux && x64))
The expression can be as complex as you need. However, the expression cannot be a regexp. It can only be a boolean expression.