How to run Jenkins jobs on multiple slaves with a single job configuration?

+1 vote

I have three different environments each containing a Jenkins Slave,

STAGE1 - slave1
STAGE2 - slave2
STAGE3 - slave3

I don't want to create three different build jobs for them.

I want to pass the slaves (slave1, slave2 and slave3) as parameters, so that if I choose slave1the job gets executed on STAGE1, and if I choose slave2 the job gets executed on STAGE2 and so on.

How to achieve that using a single Jenkins job?

I know there is multi configuration job but I am not clear on how to configure it.

It would be really helpful if I get some information on it.

Jul 8, 2018 in Jenkins by shubham
• 6,910 points
13,341 views

4 answers to this question.

+1 vote

Below is an approach which you can try.

It can be achieved using

Node and Label Parameter Plugin

It lets you create node and label parameter in the job configuration.

Node parameter contains all the nodes present in your Jenkins including master, you can select the nodes you want.

When you run the job with parameters you can select the desired node and the job will get executed in that particular node.

answered Jul 8, 2018 by Atul
• 10,250 points
+1 vote
use multijob plugin
answered Jan 3, 2019 by Ajit Jadhav
hey @Ajit, Can you please elaborate and explain?

Follow these steps to use the multijob plugin: 

  • When creating new Jenkins jobs you will have an option to create MultiJob project.
  •  In the build section, this job can define phases that contain one or more jobs.
  •  All jobs that belong to one phase will be executed in parallel (if there are enough executors on the node)
  •  All jobs in phase 2 will be executed only after the jobs in phase 1 are completed etc.
Hey thanks @Vishal, Make this an answer for better readability and understanding.
Hey @kalgi, I've written an answer, please do upvote if you think makes sense and is understandable.
0 votes

Hi, 

if i'm understood you would like to choose the slave from external parameters... 

in this case it's pretty simple 

first you should put "label" on your slaves as you mentioned "slave1" "slave2" 

then check the option "This project is parameterized" in the selected job

select string parameter and insert the code bellow in pipeline 

node (params.slave) {
    stage('test'){
        sh 'terraform --version'
    }
}

done :) 

answered Feb 11, 2019 by Liran Ben Abu
Hey Thanks, @Ben, that helped.
0 votes

Use mulijob in the following way:

  • When creating new Jenkins jobs you will have an option to create MultiJob project.
  •  In the build section, this job can define phases that contain one or more jobs.
  •  All jobs that belong to one phase will be executed in parallel (if there are enough executors on the node)
  •  All jobs in phase 2 will be executed only after the jobs in phase 1 are completed etc.
answered Apr 22, 2019 by Vishal

Related Questions In Jenkins

0 votes
1 answer

I’m facing a login error when I try to run Jenkins on Docker. How do I solve this?

You have to open the /var/log/jenkins/jenkins.log file to ...READ MORE

answered Jul 24, 2018 in Jenkins by Sophie may
• 9,900 points
452 views
0 votes
1 answer

How to run selenium script with TestNG on Jenkins?

You can build this project in Jenkins ...READ MORE

answered Jun 19, 2019 in Jenkins by Neel
• 3,010 points
271 views
0 votes
2 answers

How to auto build a job in jenkins if there is any change in code on Github repository?

To automatically run build on code commit, follow ...READ MORE

answered Jul 31, 2019 in Jenkins by Sirajul
• 45,960 points
845 views
0 votes
1 answer

running a Jenkins job on multiple virtual servers.

Your goals can be achieved by using ...READ MORE

answered May 25, 2018 in Jenkins by shubham
• 6,910 points
227 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,400 points
305 views
0 votes
1 answer
0 votes
1 answer

How to do CI integration with code review tools

Here is an explanation. If you can switch ...READ MORE

answered Mar 26, 2018 in Jenkins by Atul
• 10,250 points
163 views
0 votes
1 answer

sonar XML plugin installation failure in jenkins

You can try this link which SonarQube XML ...READ MORE

answered Jun 20, 2018 in Jenkins by Atul
• 10,250 points
72 views