0
votes

I want to run a Jenkins job on 4 different slaves (windows, linux, solaris, Mac). Instead of making 4 different jobs I want to have a single job. I can use a Node parameter to execute on different slaves. My job runs a script which uses Jenkins workspace of slave and a few other scripts. My script is in a different folder on each slave, and other required scripts are in a different folder. So now I have created 4 different jobs for each slave and hard-coded Jenkins workspace and other required scripts path.

Is there any way so that I can put all paths in some JSON-like structure and depending on slave will pick those paths? So that I will have 1 job only.

Please suggest, Thanks in advance!

2
What is the motivation for having a single job? Having four separate jobs titled my-job-windows, my-job-solaris etc seems like a good idea, especially if the job only fails on one platform where it will be much clearer to see what's happened. - robjohncox
I have 4 different project and each project has 6 different jobs. If I create separate jobs then I will have to create 96 jobs :) - rohitkadam19
You could look Matrix jobs wiki.jenkins-ci.org/display/JENKINS/Matrix+Project+Plugin or possibly even code your jobs programatically with the job dsl wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin - KeepCalmAndCarryOn

2 Answers

1
votes

my idea is to use e.g "Execute system Groovy script" to get slave value and then use if statement to assigne proper path and create parameter visible in Environment Variables:

import hudson.model.Computer
import hudson.model.StringParameterValue
import hudson.model.ParametersAction

//get slave name
def slaveName = Computer.currentComputer().getNode().name
def path

//choose path
if(slaveName.equals("slave01")){
  path = "C:"
}
if(slaveName.equals("slave02")){
  path = "/root"
}
if(slaveName.equals("slave03")){
  path = "D:"
}

//pass path as env. variable
build.addAction(new ParametersAction(new StringParameterValue('path', path)))

then you can use variable path in command: echo %path% or use Conditional BuildStep Plugin to set separable steps for each operation system and control when each step should be executed

1
votes

Jenkins is designed to check out files from a version control system (Subversion, Git, whatever) and run tasks. Instead of trying to manage separate files on separate slaves, you should put your scripts in some form of version control and let Jenkins check out the files in the workspace as part of its build process.