I've been using Jenkins and I've seen a lot of Pipeline examples (declarative ones) and I've seen some using the pollSCM
property in the Jenkinsfile
to trigger a build, like this:
triggers {
pollSCM('H/5 * * * *')
}
However, I've seen this Scan Multibranch Pipeline Triggers option when configuring a Multibranch pipeline. I'm not sure what's the difference between those.
All this problem came to me because I'm facing some cases where two builds are being triggered for the same job, and I thought it was because I have both these options configured.
Can anyone please help me understand this difference?
Thank you!
The ‘Scan Multibranch Pipeline’ trigger will scan the repository for new branches and changes in existing branches. By default it will trigger a new build for all branches which have been updated. However in the multibranch job configuration you can disable this automatic trigger for specific - or all - branches. However, please note that you have to set up the web hook for your repository so that Jenkins will be notified of any changes. As the hook setup will depend both on the Jenkins plugin used to checkout the Jenkinsfile as well as on the Git server, you will have to look this up accordingly.
The pollSCM
trigger is branch-specific. Within a Jenkinsfile you may configure different options for different branches. This option will never be able to trigger the very first build for a branch as it would need at least one build so the properties
step gets executed and the pollSCM
option set. That is: Any change here will only get effective AFTER the next build.
You can use pollSCM
trigger in two ways:
pollSCM
empty:
triggers {
pollSCM('')
}
Therefore I’d recommend to stick to the trigger based on the Multibranch branch scan - if possible. However in some special cases (e.g. if the first build on a new branch should never be built automatically) it still might be useful to use the poll SCM feature. In that case you might want to disable the automatic trigger as required.
Last but not least the poll SCM feature may use a different plugin than the Scan Multibranch Pipeline, e.g. for Bitbucket. AFAIK for Bitbucket the multibranch trigger is little bit more flexible, allows to trigger a build on more events compared the the plain Bitbucket trigger.
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