Home > Mobile >  BitBucket webhook triggers *all* Jenkins multibranch pipelines, even those who have that setting dis
BitBucket webhook triggers *all* Jenkins multibranch pipelines, even those who have that setting dis

Time:11-15

Context: We have a Jenkins 2.361.3 server and a local Bitbucket server with webhooks (on Push) that trigger multibranch pipeline jobs (declarative jenkinsfile mode) on Jenkins for every repo push. This works fine when we have a single multibranch pipeline job on Jenkins: the build is triggered for the correct branch.

New scenario: We want a second 'nightly' multibranch pipeline job on the same Jenkins server for the same Bitbucket repo, which we want to trigger on a fixed time every day for every branch that exists at that time. It should not trigger for repo pushes.

Actions taken: We created a second multibranch pipeline job, similar to the first one but now with a cron trigger in the jenkinsfile and this setting disabled: "Build when a change is pushed to BitBucket":

Build when a change is pushed to BitBucket setting disabled

This setting is still enabled for the initial job.

Expectations:

  1. On a repo push, only the initial job is triggered. The nightly job does nothing.
  2. When the cron time hits, the night job is triggered.

Actual:

  1. On a repo push, both jobs are triggered. (also after Jenkins restart)
  2. Additionally, the cron trigger works as expected.

Question: How to configure this system so that a repo push only triggers the initial job and not the nightly job?

It looks like the combination of BitBucket plugin (v223) and Multibranch Pipeline plugin (v716) does not adhere to the "Build when a change is pushed to BitBucket" setting.

Experiments performed:

  1. Disabling the "Build when a change is pushed to BitBucket" setting for both jobs (and restarting Jenkins) --> both jobs are still triggered by a repo push
  2. Remove the webhook from BitBucket and configure 'polling SCM' for both jobs --> this works but polling feels suboptimal and adds performance hits to the server.

CodePudding user response:

We solved it using the “Suppress automatic SCM triggering” property in the ‘Branch Sources’ section of the Jenkins configure page for the job, as explained enter image description here

  • Related