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,580 points
4,679 views

4 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+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,220 points
+1 vote
use multijob plugin
answered Jan 3 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 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 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,330 points
120 views
0 votes
1 answer

How to run selenium script with TestNG on Jenkins?

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

answered 21 hours ago in Jenkins by Neel
• 380 points
6 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,580 points
92 views
0 votes
1 answer

How to start Jenkins on a different port rather than 8080?

This is simple, use the following command: java ...READ MORE

answered Jul 4, 2018 in Jenkins by Sophie may
• 9,330 points
921 views
+13 votes
2 answers
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,220 points
88 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,220 points
31 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.