7
votes

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

1
So why switching on polling in the first place?Joerg S
I, Actually, have more than one projects (jenkinsfiles) in the same repo and I want to use "included_regions" and that is possible with poll scm only ? Actually I did not test, probably that will work with indexing only too ? But If I have indexing every minute, it runs on my master and I would ideally want to reduce the usage of master.Muhammad Faizan-Ul-Haq
You can also configure in the project configuration for which branches to suppress SCM triggering. That should do the trick.Joerg S
Suppress SCM Triggering did the trick, thanks for the tip @JoMuhammad Faizan-Ul-Haq

1 Answers

0
votes

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/