How to get build status of PR using BitBucket API?
The build status is on the commit, not on the PR. First you should find the latest commit of the source branch by calling /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}
. see the docs for more details
Once you have the commit id you can query the build-status api by calling /rest/build-status/1.0/commits/{commitId}
. See the docs for more details
Using API 2.0
- Get statuses: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/statuses
- Set status: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bnode%7D/statuses/build
Example:
curl --request GET \ --url https://api.bitbucket.org/2.0/repositories/piavita/com.piavita-vet.ios/pullrequests/300/statuses \ --header 'Authorization: Basic SecretKey' \ --header 'Content-Type: application/json'
curl --request POST \ --url https://api.bitbucket.org/2.0/repositories/piavita/com.piavita-vet.ios/commit/8619291af393/statuses/build \ --header 'Authorization: Basic SecretKey' \ --header 'Connection: keep-alive' \ --data '{\n "url": "http://jenkins.ddns.net:8080/job/jobName/123/",\n "state": "SUCCESSFUL",\n "key": "JENKINS"\n}'