3

I have a Build Flow project that has a DSL script to configure the flow.

This is my script:

def envVars = build.getEnvironment(listener)
def revision = envVars.get("GIT_COMMIT")
def workspace = envVars.get("WORKSPACE")
println "env vars: " + envVars
println "workspace: " + workspace
println "revision: " + revision
def command = workspace+"""/scripts/my_script.sh"""
def proc = command.execute()
proc.waitFor()
println "return code: ${proc.exitValue()}"
println "stderr: ${proc.err.text}"
println "stdout: ${proc.in.text}" 

parallel (
  { 
    build("job1", git_branch: revision)
  },
  { 
    build("job2", git_branch: revision) 
  },
  { 
    build("job3", git_branch: revision) 
  }
)

In my job configuration I have checked the Restrict where this project can be run and gave the correct slave label.

My job fails with the following error:

ERROR: Failed to run DSL Script
java.io.IOException:
  Cannot run program "/home/jenkins/workspace/my-flow-job/scripts/my_script.sh":
    error=2, No such file or directory

i have found out that the DSL script is running on the master node instead of the slave node.

How can i run the DSL on the slave? (or at least execute the script on the slave)

Thanks

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
Mr T.
  • 4,278
  • 9
  • 44
  • 61
  • Which type of „flow project“ are you referring to? [Build Flow](https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+Plugin) or [Workflow](https://wiki.jenkins-ci.org/display/JENKINS/Workflow+Plugin)? – Gerold Broser Nov 01 '15 at 13:00
  • @GeroldBroser - Im using Build Flow – Mr T. Nov 01 '15 at 13:23
  • I'm not sure about the Build Flow, the Workflow, however, has a [`node` statement for using slaves](https://github.com/jenkinsci/workflow-plugin/blob/master/TUTORIAL.md#using-slaves). – Gerold Broser Nov 01 '15 at 14:20

1 Answers1

1

You should create a FilePath for the current channel and create a launcher to launch your script. Something like the following should work for you.

def envVars = build.getEnvironment(listener)
def workspace = envVars.get("WORKSPACE")
def command = workspace+"""/scripts/my_script.sh"""
def channel = build.workspace.channel
def fp = build.workspace.toString()
def workspacePath = new hudson.FilePath(channel, fp)

def launcher = workspacePath.createLauncher(hudson.model.TaskListener.NULL);
def starter = launcher.launch().pwd(workspacePath).stdout(out).stderr(out).cmdAsSingleString(command)
starter.join()
Kebabbi
  • 174
  • 3
  • 8