I am currently reorganizing our project repository to follow a cleaner structure, and I've moved my Jenkinsfile into a dedicated '/deploy/pipeline/' directory instead of keeping it in the root folder. However, my multi-branch pipeline job is now failing because it can't find the definition file. Is there a setting in the Jenkins UI or a specific parameter in the SCM configuration that allows me to point Jenkins to a custom path for the Jenkinsfile? I want to ensure my Agile team can maintain separate build scripts without cluttering the main source code root.
3 answers
To run a Jenkinsfile from a specific folder, you need to adjust the Script Path in your Jenkins job configuration. Navigate to your Pipeline job, go to the 'Configure' section, and scroll down to the 'Pipeline' definition. If you are using 'Pipeline script from SCM', you will see a field labeled Script Path. By default, it is set to Jenkinsfile. You simply need to change this to the relative path of your file, for example: deploy/pipeline/Jenkinsfile. Once saved, Jenkins will look specifically in that directory during the "Declaration Checkout" phase. This is a standard practice in complex software development environments where you might have multiple pipelines for different environments stored in the same repository.
Are you using a standard Pipeline job or a Multi-branch Pipeline, and are you worried about how this change might affect the auto-discovery of branches across your Agile project?
You can also use the 'Remote Loader' plugin if you need to pull a Jenkinsfile from an entirely different repository, but for a subfolder, the Script Path setting is definitely the easiest way.
I agree with Barbara. For most users, just updating the Script Path in the SCM settings is the cleanest solution. It keeps everything native to the Jenkins core without needing extra plugins.
That is a great point, Michael. For Multi-branch pipelines, the configuration is slightly different but follows the same logic. You have to go into the 'Build Configuration' section of the multi-branch setup and update the 'Script Path' there. If you don't, Jenkins won't recognize any branch as having a valid pipeline, and your build history will disappear. It's also worth noting that the path is always relative to the root of the repository, so don't start the path with a forward slash.