Reputation: 59
We have a requirement where we use multibranch pipeline script i.e multibranch Jenkins file is configured across multiple branches in repo. What if we want to keep this Jenkinsfiles on multiple branches consistent, any change made in one file should be reflected across other Jenkinsfile? Any thoughts?
Upvotes: 1
Views: 893
Reputation: 4319
One simple approach is to place your pipeline code in a shared pipeline library, i.,e. the whole pipeline in a single "var". Then load the library from the same version (branch) for all branches.
In other words, your Jenkinsfile will look like:
@Library ("my_shared_lib@main") _
script {
myCiPipeline ( <optional parameters>)
}
As long as all the branches preserve that identical Jenkinsfile
, you can execute the same pipeline for all branches, and you can keep evolving the pipeline code in the shared-library.
Note that it's also possible to parameterize the myCiPipeline
var to allow a configurable logic per branch, or even to have the var itself detect the branch and act accordingly.
Upvotes: 1