rohitkadam19
rohitkadam19

Reputation: 1874

Best way to configure jenkins job running on different slaves

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!

Upvotes: 0

Views: 947

Answers (2)

jussuper
jussuper

Reputation: 3527

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

Upvotes: 1

Dave Bacher
Dave Bacher

Reputation: 15972

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.

Upvotes: 1

Related Questions