14

我有一个简单的 Jenkinsfile,我想从工作区加载一些数据。我正在使用管道插件来利用存储库中的 Jenkinsfile。构建被移植到匹配的 Jenkins 代理。当我尝试使用“readFile”时,我收到以下消息:

java.io.FileNotFoundException: /path/to/jenkins/workspace/XXXXX/project/data.json (没有这样的文件或目录)

尝试从工作区加载 Groovy 文件时,我也会收到相同的消息。

我的Jenkinsfile样子:

node('master') {
    stage "Start"
    echo "Starting"

    stage "Load File"
    def myJson = readFile "data.json"
}

任何想法为什么我无法读取这些文件?

谢谢,蒂姆

4

1 回答 1

19

When Jenkins processes a Jenkinsfile it does not automatically pull down the entire source repository. You need to execute "checkout scm" to pull down the contents of the repository. If you fail to do so no other files will be available to the pipeline script.

于 2017-11-11T00:01:55.597 回答