Context: MultiBranchPipeline Shred Library
We are working on test automation for pipeline development in our CI/CD system.
Our CI/CD system triggers builds based on commits to a bitbucket repositories having a Jenkinsfile (MultiBranch pipeline) for the micro services that we are deploying. Each commit (with a Jenkinsfile in the root) triggers a build with the multibranch plugin.
The current approach is based on using those commits also for the the shared pipeline repository containing the shared Library used for the system.
So we are using a Jenkinsfile in the sharedLibrary Project which is executed on each commit and contains code to reference itself.
@Library('sharedLibrary@currentBranch') _ // this is the relevant part
@Field def projectList = [p1, p2, ... ] // list of Projects to be tested
node('testNode') {
projectList.each { project2Test ->
def gitConfig = setupGitParameters(project2Test)
stage('checkout ' + project2Test) {
withCredentials(gitConfig){
sh """"
git clone ${project2Test}
cd ${project2Test}
git config ....
git checkout -b ${testBranch}
echo 'patch Jenkinsfile'
sed -i ${changeWhatisNeeded} Jenkinsfile
git commit -am "pipeline test mit Library ${env.BRANCH_NAME} #${env.BUILD_NUMBER}" # to force a commit
git push origin ${it.new} # this push creates a new build on the MB pipeline
"""
}
}
}
}
So I am trying to parameterize the branch of the @Library annototation to match the current Branch automatically. But I failed so far.
I am hoping for any pointers to solve this issue as it is essential for a complete test automation. As we all know, the manual editing of string constants is a proven NOGO for anything automatated!!