Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins having trouble finding JenkinsFile from SCM

I'm in the process of migrating an old Jenkins build to the new declarative pipeline. Now that I have the build up and running, I need to get the JenkinsFile from git (rather than leaving it in the Jenkins window). The issue is that Jenkins gets the file from Git, but then looks for it in the wrong location after it's pulled. This is the configuration:

enter image description here

This is the message I get in the Jenkins log:

Checking out git https://github.com/xxx/xxx_dev.git to read Jenkinsfile
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/xxx/xxx_dev.git # timeout=10
Fetching upstream changes from https://github.com/xxx/xxx_dev.git
 > git --version # timeout=10
using GIT_ASKPASS to set credentials xxx Build
 > git fetch --tags --progress https://github.com/xxx/xxx_dev.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 43bd167e0e222fb517a8deb5ce6c6c6ba3619153 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 43bd167e0e222fb517a8deb5ce6c6c6ba3619153
 > git rev-list 82e6fdcce2587aa6368d63449ac57c9f02a1f835 # timeout=10
ERROR: /u03/jenkins/jobs/xxx/jobs/Build_Main/jobs/vs2015/workspace@script/Jenkinsfile not found
Finished: FAILURE

It seems that the build agent is looking for the Jenkins file in a location on the main Jenkins server machine. The build machine is a windows machine, so /u03/jenkins/jobs/xxx/jobs/Build_Main/jobs/vs2015/workspace@script/Jenkinsfile makes no sense. Does anyone know what's going on here?

Thank!

like image 766
user3029642 Avatar asked Jul 18 '17 22:07

user3029642


People also ask

Why does Jenkins not know where to find the jenkinsfile?

For builds where jenkins is the build engine that should always be set to a "full stop" which means Jenkins uses the workspace directory it created when you setup the job in the first place, Jenkins won't know where to look for the jenkinsFile if you point it somewhere else.

Where does the build agent look for the Jenkins file?

It seems that the build agent is looking for the Jenkins file in a location on the main Jenkins server machine. The build machine is a windows machine, so /u03/jenkins/jobs/xxx/jobs/Build_Main/jobs/vs2015/workspace@script/Jenkinsfile makes no sense.

What happens when you run a Jenkins pipeline?

Assuming everything has executed successfully in the example Jenkins Pipeline, each successful Pipeline run will have associated build artifacts archived, test results reported upon and the full console output all in Jenkins. A Scripted Pipeline can include conditional tests (shown above), loops, try/catch/finally blocks and even functions.

Is Jenkins a replacement for Maven?

The Jenkinsfile is not a replacement for an existing build tool such as GNU/Make, Maven, Gradle, etc, but rather can be viewed as a glue layer to bind the multiple phases of a project’s development lifecycle (build, test, deploy, etc) together.


2 Answers

I think you named it wrong due to your mentioned filename in the question.

The script was searched in the root for your project and should be called Jenkinsfile instead of JenkinsFile.

So name the file correctly and move it into the root of your Repository.

like image 123
nemoinho Avatar answered Nov 04 '22 02:11

nemoinho


For me, Docker was renaming my 'Jenkinsfile' to 'jenkinsfile' when cloning the repo into the docker container.

The solution was to change the location of the Jenkinsfile in jenkins pipeline settings to all lowercase 'jenkins'

like image 34
Lamellama Avatar answered Nov 04 '22 04:11

Lamellama