Run Jenkins Pipeline with Code from Git

Jenkins does 2 checkouts when it looks for a pipeline script. With git, the first one is often a lightweight checkout that only gets the Jenkinsfile, rather than the whole repo, but it is 2 separate checkouts. The second checkout is the real checkout to run the Jenkinsfile.

The reason it does 2 checkouts is because it has to first look at the Jenkinsfile to see what it is you want to do and validate syntax, etc. If you are skipping an SCM checkout in your script so you can do it later or differently, then it needs to know not to do the "real" checkout. For that matter, you could theoretically pull your Jenkinsfile from one repo, skip the SCM checkout, and pull a completely different repo (or branch, or tag) and build against that, but using the Jenkinsfile from the first checkout.

So by telling Jenkins to look in the subdirectory for the Jenkinsfile, you are telling it to look in someplace in the original checkout that actually doesn't exist, because your Jenkinsfile is really in the root of your git repo.

When the second checkout is done into a subdirectory, you will need to take this into account in your Jenkinsfile, because the Jenkinsfile runs from the root of the workspace. You would need to set into the directory i.e. dir("mysubdirectory") {}, to find build files, etc.


I got the same error. By disabling Lightweight checkout in the job configuration the error was solved!


Try to omit your subdirectory from the Sript-path.

When you specify a subdirectory to clone your project, Jenkins searches the pipeline file in that directory. In your case, Jenkins is looking for the Jenkinsfile in "mysubdirectory/mysubdirectory/Jenkinsfile"


To run the Jenkinsfile Successfully from Git repo Jenkinsfile should be available in main directory path,but not in the sub directory. For Example:

.
├── .setting
├── project
└── Jenkinsfile

Jenkinsfile should not be in the Sub Directory.