Access files on a node slave from Jenkins master using Groovy

一曲冷凌霜 提交于 2019-12-04 07:43:47
jussuper

The Groovy DSL is always executed on master (in tomcats directory). Even if you install Node Label Parameter plugin and set build job to be executed on some specific slave. If you want to get access from Groovy DSL to job workspace on slave you can use channel. There's my example of creating a file in build flow job workspace:

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)

An easier way is executing file operations in downstream jobs in Execute Groovy script (not in build flow job) running on specific slave. You must have node plugin installed and pass slave name as a parameter in DSL script: build("jobA", paramNode: "nodename")

The Workflow Plugin "Originally inspired by the Build Flow Plugin" has the following section in its tutorial:

Using slaves

The parameter may be a slave name, or a single label, or even a label expression such as:

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

The following question in the Build Flow Plugin's comments is unanswered since Jan 27, 2014:

Alexander Uvizhev says:

Is there a way to specify where particular build should run? By providing a label or a node name.

Install NodeLabel parameter plugin. It Provides parameter option Label.

Then you can use this parameter in your DSL script to pass node name or value.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!