Access files on a slave node from a Jenkins wizard using Groovy

I use the Jenkins Build Flow plugin to achieve parallelization. Groovy DSL performs certain file operations. Although the Restrict where this project can be run option is set to run the job on a specific slave, DSL runs on master. This is not intended.

Can someone tell me how can I restrict DSL to work on a specified slave? Even if there is a way to access the slave file system via DSL, this should work.

In general, how can we access files on a slave node from a Jenkins wizard using Groovy?

 def fp = new hudson.FilePath(build.workspace.channel, "/srv/jenkins/workspace/myworkspace_on_slave_node") assert fp.exists() // returns true :) def ant = new AntBuilder() if (fp != null) { def scanner = ant.fileScanner { // fails here :(, says /srv/jenkins/workspace/myworkspace_on_slave_node not found // grab ALL files requested to be run fileset(dir: "$fp", includes: "**/*.java") } // now lets iterate over - print - and count test files int numFiles = 0 for (f in scanner) { println("Found file $f") numFiles++ } println("Total files $numFiles") } 

The workspace is on a node slave, but the code above does not work when I try to open a FileSet to a remote FilePath.

+5
source share
3 answers

Groovy DSL always runs on master (in the tomcats directory). Even if you install the Node Label Parameter plug-in and configure the build to run on some particular slave device. if you want to access the job workspace from the Groovy DSL on the slave, you can use the channel. Here is my example of creating a file in the workspace of the assembly execution thread:

 if(build.workspace.isRemote()){ channel = build.workspace.channel } String fp = build.workspace.toString() + "\\" + "newfile.txt" newFile = new hudson.FilePath(channel, fp) newFile.write("xyz", null) 

A simpler way is to perform file operations in downstream jobs in an Execute Groovy script (not in an assembly thread job) running on a specific slave. you must install the node plugin and pass the name of the slave as a parameter in the DSL script: build ("jobA", paramNode: "node name")

+12
source

The workflow plugin "Originally inspired by the Build Flow Plugin " has the following section in his tutorial :

Using slaves

The parameter can be a slave name or a single label or even a label expression, for example:

  node('unix && 64bit') { // as before } 

The following question in the comments of the Build Flow plugin has not been answered since January 27, 2014:

Alexander Uvezhev says:

Is there a way to indicate where a particular assembly should be performed? By providing a label or node name.

0
source

Install the NodeLabel Options Plugin . It contains the Label parameter parameter.

You can then use this parameter in your DSL script to pass the name or value of the node.

0
source

All Articles