问题 Groovy系统脚本始终在jenkins主节点中运行,而工作区是jenkins从节点中的文件路径,而该路径在主节点中不存在。
您可以通过代码验证
theDir = new File(envVars.get('WORKSPACE'))println theDir.exists()它将返回
false
如果不使用从节点,它将返回
true
解决方案 由于我们不能使用normal
File,因此必须使用
FilePathhttp://javadoc.jenkins-
ci.org/hudson/FilePath.html
if(build.workspace.isRemote()){ channel = build.workspace.channel; fp = new FilePath(channel, build.workspace.toString() + "/node_details.txt")} else { fp = new FilePath(new File(build.workspace.toString() + "/node_details.txt"))}if(fp != null){ fp.write("test data", null); //writing to file}然后它在两种情况下都有效。



