3

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!

Bruno Fernandes
  • 427
  • 2
  • 6
  • 14

2 Answers2

2

Scan Multibranch Pipeline Trigger

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.

Poll SCM

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:

  • Real polling. That is: Tell Jenkins to check the repository for changes in certain time intervals.
  • Waiting for notification by some repository hook. For this you'd need to
    1. Keep the string passed to pollSCM empty:
      triggers {
          pollSCM('')
      }
      
    2. Set up a hook on your git server to notify Jenkins (See How to configure Git post commit hook)

Recommendation

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.

Joerg S
  • 4,730
  • 3
  • 24
  • 43
  • 1 "The ‘Scan Multibranch Pipeline’ trigger will scan the repository for new branches and changes in existing branches." If new branch is created and it matches filter for branch name (or branch name regex) will the build job be triggered or not in this case??? I have set up new Configuration - after that my new branch is NOT triggered. After that I re-SAVE the configuration (I think this is related to indexing)and after that my build for that new branch is triggered. After that for every new branch job is triggered which is good. But why it didn't trigger at the first place?thx – vel Apr 15 '22 at 14:04
  • @AndreyS Sorry but I do not have a clue what is going on in your Jenkins instance. Could be some error in some configuration (not sure which could cause this), or possibly some bug in some plugin or Jenkins itself. – Joerg S Apr 21 '22 at 08:20
  • @AndreyS Just a hunch: Maybe the multibranch plugin hooks are not set-up properly? And therefore the aforementioned 'poll SCM' will trigger the build instead? – Joerg S Apr 21 '22 at 08:31
0

I think pollSCM must be the jenkins plugin

https://wiki.jenkins.io/display/JENKINS/PollSCM+Plugin

Multibranch pipeline : This is the type of pipeline, where jenkins scan and pull from all the branch within the repository , so the build will trigger automatically when some code is checked in within the branch (if you have configured it)

shashi
  • 157
  • 2