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

Bitbucket Cloud Rest API: Trace a PR to Deployment

Muffadal Hamid June 24, 2022

Hi All,

I want to calculate the lead time of a change i.e. amount of time between pr merged to develop and release.

I have explored the results "Get Deployment" & "List & Get PR" endpoints, but I am not able to trace PR to a deployment. I can see that in the UI but it is not obvious how to do it via that API. Can someone please shed some light on this topic? The docs for the rest APIs are pretty much useless.


1 answer

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 30, 2022

Hey @Muffadal Hamid ,

Thank you for reaching out to Atlassian Community.

I think the normal path to achieve this would be to call the Get Pull Request endpoint, which would return the hash of the merge commit in the field merge_commit, and then query the List Deployments endpoint for this commit.

However, I'm afraid the Deployments endpoint currently does not support filtering, so you would not be able able to filter directly using the API. We have already a feature request to implement filtering/sorting to this endpoint : 

I would suggest you to add your vote there and add yourself as a watcher in case you want to receive first-hand updates from that ticket.

As an alternative, until filtering is not implemented in that endpoint, you could use an external tool, like jq, to filter the returned deployments JSON for the merge commit. The caveat of this is that you would have to iterate through all the pages from the Deployments endpoint to get all the deployment records, before applying the filter in an external application.

Thank you @Muffadal Hamid ,

Kind regards,

Patrik S

Muffadal Hamid July 3, 2022

Thanks, @Patrik S for your response. Is there a report that I run on a weekly basis rather than using APIs?

Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 5, 2022

Hey @Muffadal Hamid ,

I'm sorry to say there's currently no native Bitbucket report to trace PRs to a deployment.

There are, however, some third-party plugins on the Marketplace, such as Awesome Graphs for Bitbucket, that can provide you some reports/analyses on the repo, but I don't think they currently track deployments.

In this case, the way to get this information would be indeed through the public Bitbucket API, once the feature BCLOUD-18729 is implemented, and you can do filtering/querying in the deployments endpoint.

Kind regards,

Patrik S

Suggest an answer

Log in or Sign up to answer
Site Admin
AUG Leaders

Atlassian Community Events