Merge check fails when commit build statuses are created via Bitbucket Cloud API

Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.

Summary

This article covers resolving the merge check failure for API commit build statuses.

Example scenario

You are running builds with a third-party CI/CD tool. These builds create a build status for the respective commit using Bitbucket's API.

You have a pull request (PR) in Bitbucket Cloud, and the merge check Minimum number of successful builds for the last commit with no failed builds and no in progress builds is enabled for the PR's destination branch.

Multiple builds have run for this PR, for example, two failed and one successful, and the merge check mentioned above fails. You expect the merge check to pass because the last of these three builds is successful.

Diagnosis

You can use Bitbucket's API to list all build statuses for the last commit of the PR's source branch.

You see three build statuses listed, two with state FAILED and one with state SUCCESSFUL.

Cause

The merge check Minimum number of successful builds for the last commit with no failed builds and no in progress builds evaluates all build statuses associated with the last commit of the PR's source branch. Since this commit has two build statuses with a status of FAILED, the merge check will fail. This is expected behavior.

Solution

If you run multiple builds on a certain commit/PR and you want only the status of the latest build to be taken into account for the merge check, you can use the same value for the API's key property when creating the build status. If a build status with the specified key already exists, this build status will be overwritten.

This is Bitbucket's API endpoint for creating a commit status.

You could use the PR ID for the key property:

API request body for "Create a build status for a commit" { "key": "PR-ID", "url": "https://jenkins.com", "state": "SUCCESSFUL", "name": "status-test-job-4" } eg: { "key": "3", "url": "https://jenkins.com", "state": "SUCCESSFUL", "name": "status-test-job-4" }

This way, if the latest build is successful, the API call will overwrite the existing FAILED build status to SUCCESSFUL, and the merge check will pass.

Note:

In case you are using Bitbucket Build Status Notifier, make sure the buildKey parameter is set to use the pull request ID, as shown above.

Updated on May 13, 2025

Still need help?

The Atlassian Community is here for you.