Monday, January 2, 2023

How to Specify Particular Jenkins Agent(Slave) to Build jobs

  

How to Specify Particular Jenkins Agent(Slave) to Build jobs

 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 node block:

node('foo') {}

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: mavennpm, etc. It can also describe what the agent is running on: windowslinuxx64, 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”: 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.


No comments:

Post a Comment

Jenkins Scripted Pipeline - Create Jenkins Pipeline for Automating Builds, Code quality checks, Deployments to Tomcat - How to build, deploy WARs using Jenkins Pipeline - Build pipelines integrate with github, Sonarqube, Slack, JaCoCo, Nexus, Tomcat

  Jenkins Scripted Pipeline - Create Jenkins Pipeline for Automating Builds, Code quality checks, Deployments to Tomcat - How to build, depl...