Skip to content

[JENKINS-75083] Build statuses do not appear in list of pull requests in Bitbucket Server #954

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

Merged
merged 1 commit into from
Jan 4, 2025

Conversation

KalleOlaviNiemitalo
Copy link
Contributor

@KalleOlaviNiemitalo KalleOlaviNiemitalo commented Jan 1, 2025

When posting a build status from a pull-request job to Bitbucket Server or Data Center, set the "ref" property to match the source branch, e.g. "refs/heads/myfeature". This fixes the problem that Bitbucket Server stopped showing build statuses in the list of pull requests when the plugin started using the newer build-status API in #930.

This PR does not change how the plugin posts a build status to Bitbucket Cloud. That case will have "ref": null for pull-request jobs, like before.

Fix JENKINS-75083.

Your checklist for this pull request

@KalleOlaviNiemitalo KalleOlaviNiemitalo changed the title Set refname in PR build status for Bitbucket Server Set "ref" in PR build status for Bitbucket Server Jan 1, 2025
@KalleOlaviNiemitalo
Copy link
Contributor Author

@nfalco79, does this need an issue in Jira?

@KalleOlaviNiemitalo
Copy link
Contributor Author

The user interface of Bitbucket Server also supports these in build statuses:

  • Statistics on the number of passed/failed/skipped tests. These can be posted to the current build-status API. I'm planning to implement that in a separate PR for Bitbucket Branch Source.
  • Hyperlinks to artifacts and to build logs. The URLs for those cannot be set via the REST API (feature request BSERV-12946). Instead, Bitbucket Server seems to recognize the Bitbucket Server Integration plugin specifically and guess the URLs. The guess isn't even correct, as the artifacts link points to the Jenkins workspace and not to the artifacts.
  • Actions. This doesn't seem to be supported in the REST API, either.

@KalleOlaviNiemitalo KalleOlaviNiemitalo force-pushed the bserv-build-status branch 2 times, most recently from ad6e5d5 to de40f20 Compare January 1, 2025 22:34
@nfalco79
Copy link
Member

nfalco79 commented Jan 1, 2025

@nfalco79, does this need an issue in Jira?

Could be better to keep track of undocumented behaviour

@KalleOlaviNiemitalo

This comment was marked as outdated.

@nfalco79
Copy link
Member

nfalco79 commented Jan 1, 2025

The user interface of Bitbucket Server also supports these in build statuses:

  • Statistics on the number of passed/failed/skipped tests. These can be posted to the current build-status API. I'm planning to implement that in a separate PR for Bitbucket Branch Source.

I know but this is a SCM plugin I did not want add dependency to the junt test (or competitor) just to provide something supported only by the server instance (for which I do not have long plan). When I added the refname attribute I had in mind a possible extension point (limited to extra fields only) to be implemented in other Bitbucket plugins.

@KalleOlaviNiemitalo
Copy link
Contributor Author

I first tried installing the HPI built from this PR, but got an error

java.io.IOException: Failed to load: Bitbucket Branch Source Plugin (cloudbees-bitbucket-branch-source 1000.0.0-SNAPSHOT (private-de40f204-kalle))
 - Update required: Git plugin (git 5.6.0) to be updated to 5.6.1-rc5349.5d1753d390a_7 or higher

Not sure whether that is by design or whether I did something wrong with Maven.

I then rebased onto 933.1.0, got commit dbf3823, built HPI from that, and installed. The result seems to be working in a pull request from the same repository, and in a pull request from a fork; I did not test a pull request to a fork. This version incorrectly shows 933.1.0 as its version number though; I should have rebased onto 737df70 instead.

It'll probably take a few days before I continue this.

@nfalco79
Copy link
Member

nfalco79 commented Jan 2, 2025

Is this related to JENKINS-74970 ?

@KalleOlaviNiemitalo
Copy link
Contributor Author

KalleOlaviNiemitalo commented Jan 2, 2025

Not really. JENKINS-74970 is specific to pull requests from a fork, and the fix would be in error handling and logging. The issue that this PR fixes is with all pull requests, whether from the same repository or from a fork.

@nfalco79
Copy link
Member

nfalco79 commented Jan 2, 2025

Not sure whether that is by design or whether I did something wrong with Maven.

It's because in master there is a bug fix that requires a release of the git-plugin (some people are waiting for it).
Branch 933.x is where I'm releasing now. So if you want I get this merged than set 933.x as the target branch, After that I will cherry pick commit into master.

@KalleOlaviNiemitalo KalleOlaviNiemitalo changed the base branch from master to 933.x January 2, 2025 09:07
@KalleOlaviNiemitalo
Copy link
Contributor Author

Filed JENKINS-75082 to request posting test results to Bitbucket Server.

@KalleOlaviNiemitalo KalleOlaviNiemitalo changed the title Set "ref" in PR build status for Bitbucket Server [JENKINS-75083] Build statuses do not appear in list of pull requests in Bitbucket Server Jan 2, 2025
@KalleOlaviNiemitalo
Copy link
Contributor Author

Filed JENKINS-75083 for the problem that this PR is intended to fix.

@KalleOlaviNiemitalo
Copy link
Contributor Author

I intend to test some more with other PR build strategies before I mark this ready to review.

@nfalco79 nfalco79 added the bug label Jan 2, 2025
@KalleOlaviNiemitalo KalleOlaviNiemitalo changed the base branch from 933.x to master January 3, 2025 15:30
@KalleOlaviNiemitalo
Copy link
Contributor Author

I rebased this PR onto master again, because 933.2.0 was released from master and not from 933.x

@KalleOlaviNiemitalo
Copy link
Contributor Author

KalleOlaviNiemitalo commented Jan 4, 2025

Manually tested scenarios with commit c8c38ab and Bitbucket Server.

  • Jenkins configured to build "Both the current pull request revision and the pull request merged with the current target branch revision":
    • Pull request from the same repository.
      • In the "Builds" column on the "Pull requests" page in Bitbucket, a progress symbol appears first, and is replaced with a checkmark when the builds complete. When I hover the mouse pointer on that, it shows a popup "2 builds passed". 🆗
      • In the "Overview" tab on the page of the pull request in Bitbucket, it shows "2 builds" and a checkmark. 🆗
      • In the "Builds" column in the "Commits" tab on the page of the pull request in Bitbucket, it shows a checkmark. When I hover the mouse pointer on that, it shows a popup "2 builds". 🆗
      • In the "Builds" tab on the page of the pull request in Bitbucket, it shows one build for "-head" and another for "-merge". 🆗
    • Pull request from fork2 to fork1 in the same user account. The parent repository is not in a personal account. Jenkins is granted READ access to both forks and configured to search for pull requests in fork1. Webhooks are not configured in these forks but a multibranch pipeline scan is manually triggered in Jenkins.
      • In the "Builds" column on the "Pull requests" page of fork1 in Bitbucket, a progress symbol appears first, and is replaced with a checkmark when the builds complete. When I hover the mouse pointer on that, it shows a popup "2 builds passsed". 🆗
      • On the "Pull requests" page of fork2 in Bitbucket, there are no pull requests. 🆗
      • On the "Branches" page of fork2 in Bitbucket, the "jenkins-test-cross-fork-pr" branch shows "OPEN" in the "Pull requests" column and a checkmark in the "Builds" column. When I hover the mouse pointer on that, it shows a popup "2 builds passed". 🆗
      • On the "Commits" page of fork2 in Bitbucket, the newest commit of the "jenkins-test-cross-fork-pr" branch shows a checkmark in the "Builds" column. When I hover the mouse pointer on that, it shows a popup "2 builds passed". 🆗
      • In the "Overview" tab on the page of the pull request in fork1 in Bitbucket, it shows "2 builds" and a checkmark. 🆗
      • In the "Builds" column in the "Commits" tab on the page of the pull request in fork1 in Bitbucket, it shows a checkmark. When I hover the mouse pointer on that, it shows a popup "2 builds". 🆗
      • In the "Builds" tab on the page of the pull request in fork1 in Bitbucket, it shows one build for "-head" and another for "-merge". 🆗
      • Merged this pull request from fork2 to fork1. Then, in the "Builds" column on the "Commits" page of fork1 in Bitbucket, it does not show any build of the commit that was built in the PR job. I suppose that is because the build status was posted to fork2 and not to fork1. It might be better to show that build here, but not showing it is also tolerable. 🆗

@KalleOlaviNiemitalo KalleOlaviNiemitalo marked this pull request as ready for review January 4, 2025 10:30
@nfalco79 nfalco79 merged commit d3c8e0d into jenkinsci:master Jan 4, 2025
15 checks passed
@jonesbusy
Copy link

for which I do not have long plan

What does this mean ? What about Data Center users ?

@nfalco79
Copy link
Member

nfalco79 commented Jan 4, 2025

I express my concern about spend double effort to support datacenter instance when there is already other plugin developed and mantained by atlassian itself. So this year I would discuss with other plugin developers about this situation and decide what do.

@jonesbusy
Copy link

The question would be, why the atlassian-bitbucket-server-integration was developed years (arround 2019) way after the bitbucket-branch-source-plugin

I tested several times since it's inception the atlassian-bitbucket-server-integration and never my needs (for example poor JobDSL integration, missing traits, not possible to override the remote name JENKINS-67890, many dependencies instead of API plugin (https://github.com/jenkinsci/atlassian-bitbucket-server-integration-plugin/blob/master/pom.xml#L54-L79) etc... And some other issues that I don't remember now

@KalleOlaviNiemitalo
Copy link
Contributor Author

I would like to keep this plugin compatible with on-premises Bitbucket for now, but I am not very experienced with Java and cannot make large changes quickly. @nfalco79, are you planning some changes to this plugin that would be easier if compatibility with Bitbucket Data Center and Server were removed?

@KalleOlaviNiemitalo
Copy link
Contributor Author

KalleOlaviNiemitalo commented Jan 4, 2025

If you are planning large changes to this plugin and don't want to spend time adapting the Bitbucket Server client to them, then I would like to know in advance so that I can try to get time for that.

If Bitbucket Server support is removed from this plugin, I think I'll try to maintain it in a private fork and port security fixes to that, while investigating whether it is feasible to port pipelines to the Bitbucket Server Integration plugin. But I don't entirely trust Atlassian's intentions with that plugin because of their stated goal to move customers to cloud services. So there's a risk that they'd make some intolerable change to it or shut it down.

@jonesbusy
Copy link

I think Bitbucket DataCenter support is crucial for this plugin and it's 70'000 installation. I doubt there is only Cloud user using it

While I highly appreciate many bugs and feature were resolved recently, I think due to this plugin adoption DataCenter support cannot be removed (As a reminder https://www.jenkins.io/project/governance/#compatibility-matters)

I also volunteer also to give help for this plugin

@nfalco79
Copy link
Member

nfalco79 commented Jan 4, 2025

I tested several times since it's inception the atlassian-bitbucket-server-integration and never my needs (for example poor JobDSL integration, missing traits, not possible to override the remote name JENKINS-67890, many dependencies instead of API plugin (https://github.com/jenkinsci/atlassian-bitbucket-server-integration-plugin/blob/master/pom.xml#L54-L79) etc... And some other issues that I don't remember now

Ok this is sad to hear, this means I have to support both scenarios for years until the support has been improved by atlassian team.

@nfalco79
Copy link
Member

nfalco79 commented Jan 4, 2025

I would like to keep this plugin compatible with on-premises Bitbucket for now, but I am not very experienced with Java and cannot make large changes quickly. @nfalco79, are you planning some changes to this plugin that would be easier if compatibility with Bitbucket Data Center and Server were removed?

I don't plan to remove any current features, but I won't implement any new features specific to the datacenter (as was done for the mirror feature), relying only on the documentation without even the possibility to test it myself. This means that the development of new features will be fast for the cloud version while it may not work properly, or at all, in the datacenter version.

What I can say is that since I will be replacing the deprecated Bitbucket server APIs with the new ones, this plugin will no longer support the server version declared in EOL. I mean... server version older than 7.x will no longer work. I don't want to complicate the logic of this plugin that not even Atlassian wants to provide support for.

Any help from datecenter users in bugfix (like this) and test like this feature is/will be welcome.

@jonesbusy
Copy link

I agreed for the EOL. I doesn't make sense to support a datacenter (or server) version that is end of life. If for some reason users cannot upgrade, they can still stay on an older version of the plugin

@nfalco79
Copy link
Member

nfalco79 commented Jan 4, 2025

OffTopic

I have a flexible plan, but what I would do in the next months is (the order does not mean priority):

  • upgrade client to apache http 5.x
  • resolve any issue in github (because I have to close it)
  • rework or remove the avatar, an aesthetic feature cannot compromise functionality
  • separate what is API and what is not
  • create some extension points so that users can provide custom implementations:
    • migrate some implementation (like plugin webhook) outside this plugin
    • allow user customize build notification (not totally) like messages, title or test result
    • webhook processor
    • ... other things, depends on the need

@KalleOlaviNiemitalo
Copy link
Contributor Author

@nfalco79 do you have experience on Apache http vs. okhttp vs. java.net.http?

I recently ported some code from okhttp to java.net.http (to minimise dependencies) and the API was pretty similar; but java.net.http apparently supports HTTP Basic authentication only and it is not possible to provide an authenticator object that would handle other authentication schemes. Although this can be worked around by making another HttpRequest.

@nfalco79
Copy link
Member

nfalco79 commented Jan 5, 2025

I want migrate to http 5.x because of this

private ThreadLocal<Integer> consecutiveFailedAttempts; // TODO call ThreadLocal#remove method is not possible using the lifecycle of apache client 4.x. Move to http client 5.x ASAP

Apache client has too many feature that jdk does not support and I have write from scratch by myself.

@KalleOlaviNiemitalo
Copy link
Contributor Author

I think Bitbucket DataCenter support is crucial for this plugin and it's 70'000 installation. I doubt there is only Cloud user using it

Perhaps a telemetry experiment could be done. The payload would be based on the "Bitbucket Endpoints" list in the "System" configuration:

  • Are there any "Bitbucket Cloud" endpoints? (yes/no)
  • Are there any "Bitbucket Server" endpoints? (yes/no)

If the plugin was installed only to satisfy dependencies, then both would be "no".

However, the results of this telemetry could be misleading if the company has migrated all projects out of Bitbucket Server but has not unregistered the defunct endpoint from Jenkins.

nfalco79 pushed a commit that referenced this pull request Jan 5, 2025
… in Bitbucket Server (#954)

Set "ref" in PR build status for Bitbucket Server
cronik added a commit to cronik/jenkinsci-bitbucket-branch-source-plugin that referenced this pull request Mar 1, 2025
The commit 7ac886d switched to the newer repository commit build
status api. This introduced a regression in the case the PR source
repository is not the same as the target, for example a person fork.
In this case the bitbucket api created from the PR head will point to
the fork repo and may result in a 401 error if the credentials don't
have the necessary permissions.

```
ERROR: Could not send notifications
com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRequestException: HTTP request error.
Status: HTTP/1.1 401
Response: {"errors":[{"context":null,"message":"You are not permitted to access this resource","exceptionName":"com.atlassian.bitbucket.AuthorisationException"}]}
```

This change will force the bitbucket api instance to be the target repo
which is the appropriate target for the notification. The old api was
commit hash centric, not project centric, so the api client owner/repo
didn't matter.

This change also reverts changes introduced by jenkinsci#954 to the refName
parameter. Since notification is on the targget repo, the head ref
branch may not exist on the target and result in no status update.

No changes were made to the Bitbucket Cloud code path.
cronik added a commit to cronik/jenkinsci-bitbucket-branch-source-plugin that referenced this pull request Mar 1, 2025
The commit 7ac886d switched to the newer repository commit build
status api. This introduced a regression in the case the PR source
repository is not the same as the target, for example a person fork.
In this case the bitbucket api created from the PR head will point to
the fork repo and may result in a 401 error if the credentials don't
have the necessary permissions.

```
ERROR: Could not send notifications
com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRequestException: HTTP request error.
Status: HTTP/1.1 401
Response: {"errors":[{"context":null,"message":"You are not permitted to access this resource","exceptionName":"com.atlassian.bitbucket.AuthorisationException"}]}
```

This change will force the bitbucket api instance to be the target repo
which is the appropriate target for the notification. The old api was
commit hash centric, not project centric, so the api client owner/repo
didn't matter.

This change also reverts some changes introduced by jenkinsci#954 to the
refName parameter. While local testing has shown that by changing
the bitbucket client to point to the target repo, setting the refName
to null works in all cases, this change has been restricted to only
cases when the source repo is the same as the target.

No changes were made to the Bitbucket Cloud code path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants