bitbucket-branch-source-plugin icon indicating copy to clipboard operation
bitbucket-branch-source-plugin copied to clipboard

Webhook for target branch update should trigger PR builds

Open andham opened this issue 4 years ago • 17 comments

  • [ x] Jenkins version

  • [ x] Plugin version

  • [ ] Bitbucket cloud

  • [ x] Bitbucket server and version

Description

Jenkins LTS 2.204.6 Bitbucket Branch Source Plugin 2.7.0 Branch API Plugin 2.5.5 Pipeline Multibranch Plugin 2.21

Bitbucket Server v6.10.4 Bitbucket Post Webhooks plugin 2.5.3

We have our multibranch builds configured with the "Merging the pull request with the current target branch revision" strategy. We use webhooks (Bitbucket Post Webhooks) to trigger multibranch builds and the multibranch project is configured to scan every 4 hours. What we see is that when the target branch is updated, it doesn't trigger a build of all PRs by the webhook. However, the scan (that happens every 4 hours) does find this change and triggers builds. This is not obvious for the users and confuses them. Also the delay for the build could be a problem as one could merge the PR before the build is triggered and if the target branch update then causes a problem for the PR this is noticed after the merge. Preferrably the webhook for the update on a branch should also trigger a build of every PR job that is configured with a merge strategy (as there is a change). (Another solution si to scan every minute but we don't want to do that as it causes unnecessary load on the Bitbucket Server.)

andham avatar Jun 04 '20 14:06 andham

Are you letting the plugin manage webhooks for you or did you set them up yourself?

deebloo avatar Jun 04 '20 17:06 deebloo

@deebloo No we're not. But we set up the webhhooks the same way and webhooks are called for changes to the target branch. It's just that we don't see that changes to the target branch causes rebuilds of any PR with this strategy as we think should happen.

andham avatar Jun 05 '20 06:06 andham

Can you share your web hook config? A couple issues I have seen have been when not using the Team/Project way of managing. I wonder if something is wrong with just multibranch

deebloo avatar Jun 05 '20 11:06 deebloo

bitbucket-webhook

Please note that we're using Bitbucket Post Webhook plugin, not native Bitbucket webhooks.

So, to be clear, the use case I'm describing is something that should be handled already? I.e. all PRs that have a merge strategy should rebuild when the target branch is updated?

andham avatar Jun 05 '20 11:06 andham

Ah ok. And that IS working when using native webhooks.

deebloo avatar Jun 05 '20 12:06 deebloo

Thanks for confirming. I tried to verify but for some reason I can't get the native webhook to work though, not sure why. We're currently not using native webhooks as they doesn't support PR updates in Bitbucket 6 (support added in Bitbucket 7).

andham avatar Jun 05 '20 14:06 andham

Even i have the same requirement and same issue. PRs wont build automatically when a target branch is updated. And also the native implementation is not working.

I tried the build strategy for this requirement but it still does not trigger the target branches.(Kept it unchecked)

image

Jenkins version: Jenkins 2.235.5 Bitbucket branch source version: 2.9.2 basic-branch-build-strategies version: 1.3.2 Bitbucket version: v6.10.4

@andham Have you found a fix or workaround for this issue? Thanks in advance!

dsakilesh avatar Sep 02 '20 06:09 dsakilesh

No, haven't found a fix or workaround unfortunately. Still an issue for us.

andham avatar Dec 07 '20 13:12 andham

@dsakilesh where can I find the "Build strategies / Change request" config section? I have a multi branch pipeline set up and can't see that section. (In my case my team explicitly doesn't want rebuilds when the target branch changes, but I have been unable to configure that yet. :( ) Thank you for your help - or anyone else who can help me out. :) (@deebloo or anyone?)

tfink-cc avatar Jun 09 '21 11:06 tfink-cc

@tfink-cc you need to install Basic Branch Build Strategies for that options. https://plugins.jenkins.io/basic-branch-build-strategies/

dsakilesh avatar Jun 09 '21 11:06 dsakilesh

Thank you @dsakilesh that will help me a lot - if it hopefully works like I am expecting it to do right now. :) (y)

tfink-cc avatar Jun 09 '21 14:06 tfink-cc

I am curious if anyone was able to get a work around or scenario to work to enable this? @tfink-cc did your config update work? We are facing a similar issue of wanting to have PRs that are outstanding automatically re-run if the target branch is updated while that PR is still open (basically if a different PR "wins" the merge race).

begoldsm avatar Nov 17 '21 18:11 begoldsm

@begoldsm my setup is working well now, but I am understanding that you are looking for the opposite behavior then what I was looking for. We didn't want PRs to run again, when the target branch had changed (for some issue involving a particular resource forming a bottleneck in our process). From my understanding the behavior you are looking for (PRs being rebuild when the target branch changes) is the default behavior anyways. 👍

tfink-cc avatar Nov 18 '21 09:11 tfink-cc

Oh that is a good call, yes, I do want the opposite (for it to trigger a rebuild of the PR when the target changes), however I didn't know this was supposed to "just work" out of the box, since it currently isn't for us :(. Can someone share a representative config that does do that? Here is what I have tried:

  1. use native webhooks (no option for changes to target branch there, but I did select source branch, to see if it worked)
  2. Use post webhooks (same deal about events missing for target branch change)
  3. Used the basic build strategies plugin to add the PR strategy and keep the "ignore" box unchecked
  4. Tried without the basic build strategies plugin as well

We are using the bitbucket branch source latest and multibranch pipelines that are configured to "merge PR with target" as the discovery strategy.

begoldsm avatar Nov 18 '21 18:11 begoldsm

Hi @begoldsm, were you able to find a solution to this problem? Currently experiencing the same issue on our Jenkins instance.

arnold-xero avatar Jun 17 '22 01:06 arnold-xero

@andham, were you able to find a solution to this?

ShankarAnush avatar Jul 02 '23 16:07 ShankarAnush

I need this feature too. anyone found a solution?

devopsmash avatar Aug 30 '23 14:08 devopsmash