1

I want to set Jenkins to launch the build in the slave who have the best environment requirements. For example I have slave 1 with JDK 7 and the slave 2 with JDK 8 and my job runs on JDK 8. I want Jenkins to building my job on the slave 2 automatically because it has JDK 8.

I didn't find anything related to this situation. I have tried some plugins like node and label parameter plugin and Parameterized Trigger Plugin.

jenkins capture

These are 2 slaves in 2 different machines. I want Jenkins to build my job in the one with the best requirements for my job.

TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

1

Solution 1

From the doc, in you pipeline, you can select an agent based on labels: agent { label 'my-defined-label' }

So you should edit your node and add appropriate labels, then target the right one in your pipeline, based on the conditions that suits you. For example if you define a label 'java8' you can then target the agent with:

pipeline{
    agent { label 'java8'}
     stages {
...

Solution 2

The other solution is to "Restrict where this job can be run" in your job's configuration. When you check that box, you can then specify the name of the slave on which you want the job to execute.

rolf82
  • 1,531
  • 1
  • 5
  • 15
  • so the first solution is a method where i can assign for each node his capabilities and for each job his requirements and then when i start building any job jenkins chooses the node with the capabilities which matches my job's requirements automatically ? – Yassine Soltani Mar 02 '20 at 08:40
  • Yes that is the idea! You still have to express you conditions in your groovy code but then indeed it is automatic. – rolf82 Mar 02 '20 at 09:11