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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,460,779
Community Members
 
Community Events
176
Community Groups

Why is the required builds merge check still failing after a successful build?

Edited

I am attempting to configure the required builds merge check on Bitbucket Server to meet the following requirements:

  1. Prevent merging PRs until one specific Jenkins job succeeds on the latest commit of the PR.
    • Note: this requirement could be relaxed to "until any Jenkins job succeeds" instead of requiring a specific job to pass, but it would be ideal to require a specific job.
  2. Do not prevent merging PRs if any other Jenkins job(s) fail on the same commit.

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:

  1. Create a new repo to test
  2. Make an initial commit on the "main" branch
  3. Create a branch "test" and make a single commit on the "test" branch
    • The commit ID was 7eceb4d213a211c86499e708a05efae644a867e3
  4. Open a PR with source branch "test" and target branch "main"
    • Confirmed the PR was ready to merge (no merge check issues)
  5. Configure a required build for key "testKey":
    required builds config.png
    • Confirmed the PR merge is blocked due to missing required build:
      blocked merge 1.png
  6. Add a successful build to the latest commit via the REST API:
    •  § 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"
      }'
  7. ❌ The PR merge was still blocked due to missing required build:

    blocked merge 2.png
    • My expectation was that the required build merge check would pass after posting the successful build result with key "testKey".
    • Confirmed the build with key "testKey" is listed as expected via the REST API:
      •  % 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.

1 answer

1 accepted

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}/builds

The 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:

  1. The "parent":"testKeyCF" is correlated with the "key":"testKeyCF1". It's important to make sure the parent and key correlate.
  2. The key should have an incrementing number after
  3. The "ref":"refs/heads/testcfb" should point to the correct branch

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 

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events