我正在使用 Jenkins Build Flow 插件来实现并行化。Groovy DSL 执行某些文件操作。即使该选项Restrict where this project can be run
设置为在特定从属设备上运行作业,DSL 也会在主设备上运行。这不是故意的。
有人能告诉我如何限制 DSL 在指定的从站上运行吗?即使有一种方法可以通过 DSL 访问从属文件系统,也应该可以。
一般来说,我们如何使用 Groovy 从 Jenkins 主节点访问节点从节点上的文件?
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")
}
工作区在从节点上,但是当我尝试将 FileSet 打开到远程 FilePath 时,上面的代码失败了。