7

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 Aug 23 '18 at 05:48
  • 1
    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 Aug 23 '18 at 07:21
  • 4
    You can also configure in the project configuration for which branches to suppress SCM triggering. That should do the trick. – Joerg S Aug 23 '18 at 11:03
  • 1
    Suppress SCM Triggering did the trick, thanks for the tip @Jo – Muhammad Faizan-Ul-Haq Aug 23 '18 at 11:39

1 Answers1

2

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/

Thiyaga
  • 36
  • 5
  • Although, it is fine for time based build but the setting will abort the build if the branch indexing event caused by pull-request or merge event. – Raunak Kapoor Dec 20 '22 at 19:59