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

+2 votes

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 9, 2018 in Jenkins by shubham
• 7,340 points
47,620 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 9, 2018 by Atul
• 10,240 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
• 10,620 points
3,594 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,020 points
4,101 views
+1 vote
3 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
• 59,230 points
78,901 views
0 votes
1 answer

how to create a job using jenkins for Sign the puppet certificate on master ?

Take a look at this  https://fullstack-puppet-docs.readthedoc ...READ MORE

answered May 29, 2020 in Jenkins by Sirajul
• 59,230 points
1,169 views
+15 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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,062 views
+2 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 27, 2018 in Jenkins by Atul
• 10,240 points
1,436 views
0 votes
1 answer

sonar XML plugin installation failure in jenkins

You can try the SonarQube XML plugin. ...READ MORE

answered Jun 21, 2018 in Jenkins by Atul
• 10,240 points
1,000 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP