Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jenkins pipeline unable to read files

I have a simple Jenkinsfile where I want to load some data from the workspace. I am using the pipeline plugin to leverage the Jenkinsfile inside of the repository. The build is farmed off to a matching Jenkins agent. When I try to use "readFile" I get the following message:

java.io.FileNotFoundException: /path/to/jenkins/workspace/XXXXX/project/data.json (No such file or directory)

I also get the same message when trying to load a Groovy file from the workspace.

My Jenkinsfile looks like:

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

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

Any ideas why I can't read these files?

Thanks, Tim

like image 417
timcrider Avatar asked May 03 '16 19:05

timcrider


1 Answers

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.

like image 75
timcrider Avatar answered Oct 06 '22 13:10

timcrider