I am attempting to configure the required builds merge check on Bitbucket Server to meet the following requirements:
I was originally using the minimum successful builds merge check, but that does not meet requirement #2 because it prevents merging PRs if any failed builds appear (even if there is also 1 successful build).
The required builds merge check configuration is not working as I expected. It seems to fail to recognize a successful build regardless of what build key I specify.
I set up a simplified test to confirm what I was seeing with these steps:
§ curl --location --request POST 'https://<redacted>/rest/build-status/latest/commits/7eceb4d213a211c86499e708a05efae644a867e3' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic <redacted>' \
--header 'Cookie: BITBUCKETSESSIONID=<redacted>' \
--data-raw '{
"state": "SUCCESSFUL",
"key": "testKey",
"name": "testName",
"url": "https://www.lutron.com",
"description": "testDescription"
}'
% curl --location --request GET 'https://<redacted>/rest/build-status/latest/commits/7eceb4d213a211c86499e708a05efae644a867e3' \
--header 'Accept: application/json' \
--header 'Authorization: Basic <redacted>' \
--header 'Cookie: BITBUCKETSESSIONID=<redacted>'
{"size":1,"limit":25,"isLastPage":true,"values":[{"state":"SUCCESSFUL","key":"testKey","name":"testName","url":"https://www.lutron.com","description":"testDescription","dateAdded":1672868354718}],"start":0}
What is missing from this test to allow the required builds merge check to pass? I'm hoping that a resolution to this simple example will help me find the issue when attempting similar config on my real repo.
I got an answer from Atlassian support on this so I'm sharing it here in case it helps someone finding this question later.
My testing was using a deprecated API to report the build status, deprecated in Bitbucket 7.14:
https://developer.atlassian.com/server/bitbucket/reference/api-changelog/#build-status-1
Build-status
In Bitbucket 7.14, the following new REST end-points are added for build-status:GET /rest/api/latest/projects/{projectKey}/repos/{repositorySlug}/commits/{commitId}/builds
DELETE /rest/api/latest/projects/{projectKey}/repos/{repositorySlug}/commits/{commitId}/buildsThe following REST end-points are deprecated:
GET /rest/api/1.0/build-status/latest/commits/{commitId}
POST /rest/api/1.0/build-status/latest/commits/{commitId}
Using the new API worked as expected and allowed the required builds merge check to pass. Here's the example request that the support representative used to test it:
curl -u admin:"the password" --location --request POST 'https://<url>/rest/api/1.0/projects/~admin/repos/tr/commits/c558c598cb74376ecff6347fe2c3dedae8eaba01/builds' \
--header 'Content-Type: application/json' \
--data-raw '{"key":"testKeyCF1","state":"SUCCESSFUL","url":"https://bamboo.url/browse/TEST-REP1-3","buildNumber":"1","description":"Unit test build","duration":1500000,"lastUpdated":1359075920,"name":"Database Matrix Tests","parent":"testKeyCF","ref":"refs/heads/testcfb","testResults":{"failed":0,"skipped":0,"successful":1}}'
And some important details shared about the data:
I also confirmed that the Bitbucket Branch Source plugin used with Jenkins to report build status in real use cases (as opposed to my testing using curl) also uses the deprecated API. This explains why the required builds merge check was not working in real use cases as well.
https://github.com/jenkinsci/bitbucket-branch-source-plugin/blob/b8128a1921b48a4e319a1a3c9153353959f397ae/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/server/client/BitbucketServerAPIClient.java#L156
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.