We have a bunch of projects, each lying in it's own git repository. I want to build them with Jenkins 2 multibranch pipeline jobs. One job for every repository. The Jenkinsfile for every project looks the same and changes made to the build process need to be rolled out to every project. These changes can be small fixes in a build step or adding a complete new build step.
To keep maintainabillity as high as possible i would like to use just one Jenkinsfile and include it in every project, so i only have to modify this single Jenkinsfile to modify all projects build workflow.
Is it possible (and how) to achieve this goal. Deploy one single Jenkinsfile to a bunch of repository so that i only have to change one file to change all build jobs?
I know that there is the possibility to use shared libraries
, where i could define the execution code of the build steps. But if want to add a complete new build step i still would have to modify all jenkinsfiles which i don't want to do. So I am really looking for a way to share the whole Jenkinsfile for all projects, if possible.
It is not only possible to put pipeline steps into a shared library. It is also possible to put your complete pipeline as global variable into a shared library. With this approach your Jenkinsfile in each repository needs only one line of code then. And you can modify the pipeline of all projects in one single place (in the shared library).
See an example in: Jenkins pipeline template
Jenkins documentation on this topic: https://jenkins.io/doc/book/pipeline/shared-libraries