jenkins - 詹金斯在工作区中看不到现有文件
问题描述
我正在尝试在某项工作中读取一些文件。在 Jenkins 中使用脚本控制台我看到以下内容:
- Jenkins 可以访问作业中的必要构建
file = new File ("${Jenkins.instance.getItemByFullName('Build mac pipelines/sand box').lastBuild}")
结果将是:
Result: Build mac pipelines/sand box #44
- 但是当我尝试像这样读取文件 groovy1.txt 时:
file = new File ("${Jenkins.instance.getItemByFullName('Build mac pipelines/sand box').lastBuild}/groovy1.txt").text
然后詹金斯找不到 groovy1.txt 文件
Build mac pipelines/sand box #44/groovy1.txt (No such file or directory)
它发生在这样的文件存在时,截图
为什么会发生以及如何读取文件?
解决方案
工作区路径不包含内部版本号。
每个构建都使用相同的工作区。
如果可能,请查看安装 Jenkins 的机器的文件系统。
编辑
如果我没记错的话,你甚至不需要工作区的绝对路径,你可以试试file = new File ("./groovy1.txt").text
.
请在此处查看一些建议:Get absolute path to workspace directory in Jenkins Pipeline plugin
推荐阅读
- php - 在 Eloquent 资源中使用分页会在 Laravel 中引发 Undefined Property $id 错误
- python - python将方法名称传递给函数
- angular - Angular2 ngFor,存在时属性未定义
- regex - 匹配字符串和一些字母的正则表达式
- excel - 如果用户窗体中出现“错误”,则取消任务
- c# - 准备完成的对象被阻止
- vhd - 格子钻石显示合成退出 9
- python - 如何对包含数字的字符串列表进行数字排序?
- jquery - 带有 WordPress 和 Webpack 的 jQuery
- java - 从 double 到 int 的可能有损转换;爪哇;链表