Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 702
Muhammad Faizan-Ul-Haq Avatar asked Aug 22 '18 13:08

Muhammad Faizan-Ul-Haq


People also ask

What is Jenkins branch indexing?

Branch indexing discovers new or deleted branches. In the job configuration (Branch Sources > Property strategy), you can activate Suppress automatic SCM triggering, which will not automatically build new branches.

What is the difference between pipeline and Multibranch pipeline in Jenkins?

Jenkins Pipeline Vs. Multibranch Pipeline. A multibranch pipeline is meant for building multiple branches from a repository and deploy to multiple environments if required. A pipeline job supports both pipeline steps to be added in Jenkins configuration and form SCM.

What is the use of Multibranch pipeline in Jenkins?

The Multibranch Pipeline project type enables you to implement different Jenkinsfiles for different branches of the same project. In a Multibranch Pipeline project, Jenkins automatically discovers, manages and executes Pipelines for branches which contain a Jenkinsfile in source control.


1 Answers

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/

like image 200
Thiyaga Avatar answered Oct 26 '22 12:10

Thiyaga