通过奴隶上的 jenkins post-groovy 脚本写入文件
我想做一些非常简单的事情:通过 jenkins groovy 构建后脚本插件
def props_file = new File(manager.build.workspace.getRemote() + "/temp/module.properties")
def build_num = manager.build.buildVariables.get("MODULE_BUILD_NUMBER").toInteger()
def build_props = new Properties()
build_props["build.number"] = build_num
props_file.withOutputStream { p ->
build_props.store(p, null)
}
最后一行失败,因为文件不存在。我认为这与指向主执行器的输出流有关,而不是与远程工作区有关,但我不确定:
Groovy script failed:
java.io.FileNotFoundException: /views/build_view/temp/module.properties (No such file or directory)
我是否没有正确写入文件?
I'd like to do something very simple: Create/write to a file located in the remote workspace of a slave via the jenkins groovy post-build script plug-in
def props_file = new File(manager.build.workspace.getRemote() + "/temp/module.properties")
def build_num = manager.build.buildVariables.get("MODULE_BUILD_NUMBER").toInteger()
def build_props = new Properties()
build_props["build.number"] = build_num
props_file.withOutputStream { p ->
build_props.store(p, null)
}
The last line fails, as the file doesn't exist. I'm thinking it has something to do with the output stream pointing to the master executor, rather than the remote workspace, but I'm not sure:
Groovy script failed:
java.io.FileNotFoundException: /views/build_view/temp/module.properties (No such file or directory)
Am I not writing to the file correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在写入从属设备时,您需要首先检查通道,然后才能成功创建文件句柄并开始读取或写入该文件:
希望这会有所帮助!
While writing onto slave you need to check the channel first and then you can successfully create a file handle and start reading or writing to that file:
hope this helps!
在插件页面(您提供的链接)上搜索单词
The post build plugin running on the manager and do it if you are working with Slaves!
并查看是否那里的解决方法有帮助。Search for words
The post build plugin runs on the manager and doing it as you say will fail if you are working with slaves!
on the plugin page (the link to which you've provided) and see if the workaround there helps.文件夹
/views/build_view/temp
是否存在?如果没有,您将需要执行
new File( "${manager.build.workspace.remote}/temp" ).mkdirs()
Does the folder
/views/build_view/temp
exist?If not, you will need to do
new File( "${manager.build.workspace.remote}/temp" ).mkdirs()