Multibranch pipelines are great. They ease the continuous deployment for feature branch development strategies. If you are using Jenkins, ne common issue you might experience with Jenkins multibranch pipelines is that when you create one, all branches are built automatically. This might be problematic as some repositories might have multiple branches, which puts high load on the Jenkins resources. and if you have some deployment step to the cloud, all branches will be triggered and trust it’s a pain to stop all of them.
Index Filter Condition
This happens because when you create nultibranch pipelines, Jenkins will build pipelines because of indexing triggers. You can use this condition inside your Jenkinsfile to skip build steps when it’s an indexing trigger.
if (currentBuild.rawBuild.getCauses().toString().contains('BranchIndexingCause')) {
print "Skipping Index Build"
currentBuild.result = 'Skipping Index Build'
return
}
pipeline {
....
}
You might need to approve rawBuild and getCauses functions to be executed, to do so navigate to Jenkins > Manage jenkins > In-process Script Approval.
You are all set. Now multibranch pipelines won’t trigger build job steps when they re created.