I have a multibranch pipeline. I have configured Trigger in jenkinsFile properties:
pipelineTriggers([pollSCM('H/2 * * * *')])])
The multibranch pipeline is configured to "scan Multibranch Pipeline Triggers" periodically. Expected behavior: Trigger builds only on build triggers configured through jenkinsFile Actual: It triggers build on Poll SCM and also on "re-indexing" for the same commit.
We are using
Jenkins: 2.107.1
git plugin: 3.8.0
Pipeline multibranch: 2.17
Branch indexing discovers new or deleted branches. In the job configuration (Branch Sources > Property strategy), you can activate Suppress automatic SCM triggering, which will not automatically build new branches.
Jenkins Pipeline Vs. Multibranch Pipeline. A multibranch pipeline is meant for building multiple branches from a repository and deploy to multiple environments if required. A pipeline job supports both pipeline steps to be added in Jenkins configuration and form SCM.
The Multibranch Pipeline project type enables you to implement different Jenkinsfiles for different branches of the same project. In a Multibranch Pipeline project, Jenkins automatically discovers, manages and executes Pipelines for branches which contain a Jenkinsfile in source control.
I guess we can not stop the build trigger from scanning. But our build should be able to identify and stop the additional build.
// execute this before anything else, including requesting any time on an agent
if (currentBuild.getBuildCauses().toString().contains('BranchIndexingCause')) {
print "INFO: Build skipped due to trigger being Branch Indexing"
currentBuild.result = 'ABORTED' // optional, gives a better hint to the user that it's been skipped, rather than the default which shows it's successful
return
}
Source: https://www.jvt.me/posts/2020/02/23/jenkins-multibranch-skip-branch-index/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With