Delete build status API unable to delete a specific build in Bitbucket Data Center

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

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

The build status remains visible in the Bitbucket GUI even after deleting it via the delete build status API.

Refer to Delete a specific build statusto get additional information on this API.

Environment:

Bitbucket Data Center 8.8.1

Diagnosis

When a user executes the DELETE API, it is executed with the 204 response code. This response code is expected in this API.

1 2 curl -s -o /dev/null -w "%{http_code}" -u admin --request DELETE --url 'https://linux-47991.prod.atl-cd.net/bitbucket/rest/api/latest/projects/PRO1/repos/repo5/commits/8944d2272a83a669ce2dee52f7fa395f86fa9a74/builds?key=New1' -v --header 'Accept: application/json' 204

On enabling Database debug log, the following delete query can be seen in atlassian-bitbucket.log. Bitbucket runs the delete query with the correct repository_id, commit_id, and build_key.

Refer toEnable SQL Query LoggingKB article to know more details on enabling and disabling the database debug logs. 

1 2 3 4 2023-07-28 14:51:17,616 DEBUG [http-nio-7990-exec-4] user01 @1HTW4OBx891x559x0 172.29.XX.XX,172.50.XX.XX "DELETE /rest/api/latest/projects/PRO1/repos/repo5/commits/8944d2272a83a669ce2dee52f7fa395f86fa9a74/builds HTTP/1.1" org.hibernate.SQL delete from bb_build_status where repository_id=? and commit_id=? and build_key=? 2023-07-28 14:51:17,616 TRACE [http-nio-7990-exec-4] user01 @1HTW4OBx891x559x0 172.29.XX.XX,172.50.XX.XX "DELETE /rest/api/latest/projects/PRO1/repos/repo5/commits/8944d2272a83a669ce2dee52f7fa395f86fa9a74/builds HTTP/1.1" o.h.type.descriptor.sql.BasicBinder binding parameter [1] as [INTEGER] - [13] 2023-07-28 14:51:17,616 TRACE [http-nio-7990-exec-4] user01 @1HTW4OBx891x559x0 172.29.XX.XX,172.50.XX.XX "DELETE /rest/api/latest/projects/PRO1/repos/repo5/commits/8944d2272a83a669ce2dee52f7fa395f86fa9a74/builds HTTP/1.1" o.h.type.descriptor.sql.BasicBinder binding parameter [2] as [VARCHAR] - [8944d2272a83a669ce2dee52f7fa395f86fa9a74] 2023-07-28 14:51:17,616 TRACE [http-nio-7990-exec-4] user01 @1HTW4OBx891x559x0 172.29.XX.XX,172.50.XX.XX "DELETE /rest/api/latest/projects/PRO1/repos/repo5/commits/8944d2272a83a669ce2dee52f7fa395f86fa9a74/builds HTTP/1.1" o.h.type.descriptor.sql.BasicBinder binding parameter [3] as [VARCHAR] - [New1]

On checking the DB records against this commit_id and build_key, it is seen that the repository_id column has a NULL value and due to that DELETE query mentioned above couldn't delete the row.

1 2 3 4 5 6 select commit_id,build_key,repository_id from bb_build_status where commit_id='8944d2272a83a669ce2dee52f7fa395f86fa9a74' and build_key='New1'; +----------------------------------------+---------+-------------+ |commit_id |build_key|repository_id| +----------------------------------------+---------+-------------+ |8944d2272a83a669ce2dee52f7fa395f86fa9a74|New1 |null | +----------------------------------------+---------+-------------+

Cause

If the plugin responsible for sending build results from Jenkins uses the API endpoint listed below, then the build statuses are stored with a NULL value in the repository_id column. One such plugin is Bitbucket Server Notifier which uses this deprecated endpoint.

1 https://<bitbucket-base-url>/rest/build-status/1.0/commits/<commit-hash>

This API endpoint was deprecated after a new endpoint was introduced in Bitbucket 7.4. The old API endpoint does not populate most of the values(including repository_id) in the columns of the bb_build_status table. Refer to the API Change Log for more details on the New endpoint.

Solution

  • Back upyour data before performing any delete operation in DB.

  • If possible, test the queries on a staging server first.

  • If the repository_id column is NULL then the DELETE build status API can't delete the build status. In such a situation, specific build status has to be deleted manually from the DB.

  • Use Bitbucket Server Integration or any other plugin which uses the following API endpoint to store the build status. It populates the repsotiry_id column in the database and hence can be deleted by DELETE API. Refer to Build Status API for more details on the new endpoint to store build status in Bitbucket.

Updated on March 13, 2025

Still need help?

The Atlassian Community is here for you.