Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to overwrite bitbucket notification status for pull requests

Jimmy.Diep September 20, 2023

I have a webhook  that will trigger Jenkins build when there is a new or updated pull requests for the repos.

It will trigger the bitbucket notification to show the build status.

However, when the PR has multiple updates, it will trigger multiple builds that are tied to the PR.  This is a problem as if any of the builds fails or never completes for a reason, the PR is stuck as there is a branch restriction set:

"Check the last commit for at least 1 successful build, no failed builds, and no in progress builds"

ie.


Screenshot 2023-09-20 at 11.10.00 AM.png

4 builds were successful after the 1st build got stuck in a never completed state.  This prevented the PR from being merged

 

Screenshot 2023-09-20 at 11.25.57 AM.png

This PR has 6 builds that were unsuccessful, but the last one is successful.  However, since it doesn't pass the PR requirements for merging:

"Check the last commit for at least 1 successful build, no failed builds, and no in progress builds"

It is not allowed to merge.

 

I am using the bitbucketStatusNotify function, passing in buildState, reposSlug, and commitID.

ie.

bitbucketStatusNotify(buildState: "SUCCESS", repoSlug: "my-repos", commitId: "xyzzy")

 

Is there a way to cancel previous build states and only have the latest one tied to the PR?

 

Thanks.

 

2 answers

1 accepted

1 vote
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 22, 2023

Hi Jimmy,

You can get info about the commit statuses (including their key) of a certain commit with the following API endpoint:

Example call:

curl -u username:app-password --request GET \
--url 'https://api.bitbucket.org/2.0/repositories/workspace-id/repo/commit/7c47933/statuses' \
--header 'Accept: application/json'

You can then use the following API endpoint to update a certain status:

Example call:

curl -u username:app-password --request PUT \
--url 'https://api.bitbucket.org/2.0/repositories/workspace-id/repo/commit/7c47933/statuses/build/some-key' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"state": "SUCCESSFUL"
}'

You can see all available values for state in the last link I shared if you select + Show child properties for Commit Status > expand the state property.

Please feel free to let me know if you have any questions!

Kind regards,
Theodora

Jimmy.Diep September 22, 2023

Awesome!  Thank you very much!

0 votes
Jimmy.Diep September 21, 2023

I found there is a buildKey field that is unique for the link.


https://github.com/jenkinsci/bitbucket-build-status-notifier-plugin

 

Is there a way to find the buildKey value for previous builds?  Knowing this value, I can change the build state of the existing builds linked to the PR.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events