Ash
Ash

Reputation: 53

How to get build status of PR using BitBucket API?

Not getting Build job details/status of the PR when using Bitbucket API for any pull request

Here is my API URL:

https://example.com/rest/api/1.0/projects/{projectkey}/repos/{reposlug}/pull-requests/{pullrequestID}

How Build status looks like on GUI:

enter image description here

I also tried below methods to get the Build status but no luck

/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/pull-requests
/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks

So I wanted to get whether build status of any PR whether it is Success or Fail

Thanks in Advance for your answers.

Upvotes: 4

Views: 11159

Answers (2)

Vlad
Vlad

Reputation: 6732

Using API 2.0

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}'

Upvotes: 3

Yuri G.
Yuri G.

Reputation: 4648

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

Upvotes: 11

Related Questions