jenkinsci / bitbucket-branch-source-plugin

Bitbucket Branch Source Plugin
https://plugins.jenkins.io/cloudbees-bitbucket-branch-source
MIT License
216 stars 352 forks source link

Bitbucket multibranch project doesn't disable the branch job after creating a PR #539

Open sennetheunisporphy opened 2 years ago

sennetheunisporphy commented 2 years ago

Jenkins and plugins versions report

Hello

I am using Jenkins on kubernetes using a helm chart together with JCASC. I am using the lts-jdk11 image (Jenkins version 2.319.1).

I have configured my multibranch project with the Bitbucket branch source. I use the following properties: discover pull requests "HEAD", discover branches "EXCLUDE_PRS". Its all working fine, when I create a branch, it gets checked out and ran. But when I create a PR, I noticed that the Pull Request is discovered and ran, but the branch itself (under Branches tab) is not being disabled. Is there something I need to configure or is this normal behaviour?

What Operating System are you using (both controller, and any agents involved in the problem)?

Controller is running in EKS.

Reproduction steps

Setup multibranch project for a Bitbucket single repo. Select Discover branches "EXCLUDE_PRS" Select Discover prs "HEAD"

Expected Results

When I create a PR, the branch itself (under branches) would be disabled. (Project rescan triggered) When I decline the PR, the PR is disabled (this is the case), but the branch itself is not rescanned.

Actual Results

When I create a PR, the multibranch branch project is not rescanned so the branch is not being disabled. When I decline a PR, the multibranch branch project is not rescanned so the branch is not being rediscovered

Anything else?

No response

lifeofguenter commented 2 years ago

I never was able to get this working reliably - even with the github-branch-source plugin. It might be a limitation in the design how Jenkins handles events.

Usually what I do to avoid this is adding a "named build strategy" to explicitly only build branches I want to build (outside of PRs), usually this would be either the default or a dev branch:

Screenshot 2022-01-07 130553

sennetheunisporphy commented 2 years ago

@lifeofguenter so I would have to add the third one for named branches? So, branch discovery -> EXCLUDE_PRS pr discovery -> HEAD Named -> master, feature/*

As in our case they want everything to run on Jenkins from the moment the branch is created

christopo commented 2 years ago

Hi @lifeofguenter, as this is the origin of my duplicated issue #574 I'm asking here.

Is it possible to trigger branch-(re)indexing once web hook has been received to enforce deletion of the branch?

jonaz commented 2 years ago

This is nasty bugg. When we push a new branch it starts building that branch immediately and if i create a PR 20 seconds later for that branch, both the branch build and the PR build will continue to run and waste CI resources. I would expect the branch do be stopped and deleted when a PR is opened. Or ever better that jenkins understands that it is a PR that have been added to an existing build.

My hooks in bitbucket are setup like this: "%s/bitbucket-scmsource-hook/notify?server_url=%s" with those events:

            "repo:refs_changed",
            "pr:opened",
            "pr:merged",
            "pr:declined",
            "pr:deleted",
            "pr:modified",
            "pr:reviewer:updated",
            "pr:from_ref_updated",

The problematic event is repo:refs_changed. If i enable that this problem occurs, and if i dont enable it it will only build PRs and never for example master after i merge to master.