'What is the difference between using the pollSCM and the Scan Multibranch Pipeline Triggers in Jenkins?

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!



Solution 1:[1]

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.

Solution 2:[2]

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)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 shashi