首页 > 解决方案 > 詹金斯在工作区中看不到现有文件

问题描述

我正在尝试在某项工作中读取一些文件。在 Jenkins 中使用脚本控制台我看到以下内容:

file = new File ("${Jenkins.instance.getItemByFullName('Build mac pipelines/sand box').lastBuild}")

结果将是:

Result: Build mac pipelines/sand box #44

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

解决方案


工作区路径不包含内部版本号。

每个构建都使用相同的工作区。

如果可能,请查看安装 Jenkins 的机器的文件系统。

编辑

如果我没记错的话,你甚至不需要工作区的绝对路径,你可以试试file = new File ("./groovy1.txt").text.

请在此处查看一些建议:Get absolute path to workspace directory in Jenkins Pipeline plugin


推荐阅读