Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branches and PRs overwrite each other statuses in Bitbucket allowing code to be merged before it is fully tested #324

Open
3 of 4 tasks
muppet3000 opened this issue Jun 30, 2020 · 8 comments · May be fixed by #451
Open
3 of 4 tasks

Comments

@muppet3000
Copy link

Your checklist for this issue

  • Jenkins version

  • Plugin version

  • Bitbucket cloud

  • Bitbucket server and version

Description

  • Jenkins version: 2.235.1 (The Jenkins version is irrelevant)

  • Plugin version: Any version >= 2.4.3 (we are currently using 2.8.1-rc646.71e4d09c0b37 as a result of this issue: Pull-Requests no longer working on BitBucket Server 7.0 #287)

  • Bitbucket server and version: Server version 7.1.1 (The Bitbucket version is irrelevant)

  • Issue: When a feature branch and a pull request branch are both running at the same time, whichever one finishes first causes the status in bitbucket to be updated, this will then be overwritten by the other job when it finishes. Therefore, failures may go undiagnosed either because they are overwritten by the second job, or be ignored because the code is merged before all branches have finished building.

TLDR

The following issue occurs when Jenkins is configured to use the discover branch strategy "Exclude branches that are also filed as PRs"

When a user pushes code to a feature branch the corresponding job is triggered in Jenkins. If the user then creates a pull request in BitBucket whilst this branch is building it will cause another build to get triggerd in Jenkins. All of this is expected behaviour.

However, the "build status" of the PR in Bitbucket only shows 1 build. It shows the status of whichever build updated it last e.g. it will show the status of the feature branch until the PR is triggered, then it wil show the status of the PR, then, when the feature branch completes (but the PR is still building) it will show the 'completed' status of the feature branch, despite the fact there is still a PR job running.

This behaviour means that for those of us who run extended sets of tests for PRs there is a window between the feature branch completing and the PR branch completing where the status in Bitbucket is shown as "passed", when in reality there is still the possibility of a failure being reported by the PR job.

I have tracked this down to the following PR: #172 which was to address the following Jenkins ticket: https://issues.jenkins-ci.org/browse/JENKINS-45643
This was subsequently released in version 2.4.3 of this plugin and has been there ever since.

Now, having been a victim of JENKINS-45643 in the past myself (although I've always worked around it by either deleting the PR and triggering the feature branch manually, or hitting the Bitbucket REST API to override the status of the failed/pending job) I understand why the approach in PR-172 was taken. However, it overlooked the need for the status of the PR build to take precedence over all over branches.

This creates a difficult situation on how to proceed as we don't want to introduce a regression to the plugin by removing this functionality. That said, the position we're currently in is that users of the plugin are potentially being misled by the status of jobs appearing in Bitbucket.

One 'workaround' that I have considered is to stop using the "Exclude branches that are also filed as PRs" and just use "All branches" but that will massively duplicate the number of builds happening in Jenkins.

Proposed solution

My proposal (if it's possible to implement) would be to add a tickbox in the configuration of the plugin (much like the recent additions of "Call Can Merge" and "Call changes api") which would allow users of the plugin to "opt in" to using the older style of naming where feature branches and PR branches show uniquely in Bitbucket, perhaps something like "Branches and PRs use different Bitbucket identifiers".

I believe this would also resolve this issue: #298

@viceice
Copy link
Member

viceice commented Jun 30, 2020

I would also like a predictable (configurable) identifier as we would like to add bots, which depends on specific build states to be passed before they do something

@sacchettom
Copy link

I'm not sure this would be a wise move. The thing is: how much massive is this massive duplication? Once a branch is turned into a PR, I would not expect massive changes - if there are, better to decline and start anew. The current setup allows Jenkins to delete the branch job safely - you won't need it later. The previous setup, as you noted, would possibly generate a situation that you need to manually fix, which occurs whenever the branch job fails, reports that, and you then need to re-run it but it's been deleted by Jenkins. As noted, removing the PR's branch job automated deletion would fix your issue (I do agree that the online help and docs should accurately describe this behaviour though).
As would also a different option like:

  • halt an ongoing branch job when the PR is created (but this is always some sort of risky approach and I'm not sure of what's available in jenkins api)
  • change the job result reporting querying bitbucket first with a logic like if (not on branch) or (no PR from this commit exist) -> send notification

#298 doesn't seem to have attracted much interest, but looking at their workflow they either probably want to also build the original branch, or the original branch build is actually a small overhead compared to the PRs.

@muppet3000
Copy link
Author

muppet3000 commented Sep 7, 2020 via email

@sams-gleb sams-gleb linked a pull request May 25, 2021 that will close this issue
1 task
@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 16, 2022
@carpnick
Copy link

bump.

@stale stale bot removed the stale label Oct 10, 2022
@nightm4re94
Copy link

bump.

@pablofrias
Copy link

bump

1 similar comment
@Skamandros
Copy link

bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants