Branch Indexing in jenkins multibranch pipeline triggers extra build, which is already built by poll SCM
Asked Answered
I

1

8

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

Ilarrold answered 22/8, 2018 at 13:1 Comment(4)
So why switching on polling in the first place?Coplin
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.Ilarrold
You can also configure in the project configuration for which branches to suppress SCM triggering. That should do the trick.Coplin
Suppress SCM Triggering did the trick, thanks for the tip @JoIlarrold
K
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/

Kutaisi answered 24/8, 2021 at 11:15 Comment(1)
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.Sweetbrier

© 2022 - 2024 — McMap. All rights reserved.