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

Webook, API notify pipeline status

rwilliams
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 16, 2019

Is there some way through bitbucket to push a pipeline status (completed or failed) message through a webhook or any way at all?

Alternatively can I poll/query the bitbucket API to get the status of a pipeline?

1 answer

1 accepted

0 votes
Answer accepted
seanaty
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 16, 2019

In the UI, in repository > settings > webhook you can create a webhook for 'build status created' and 'build status updated'

Pipelines sets build status, so that would trigger these events. (Note: other CI integrations can also trigger build statuses).

 

You can also set these hooks via the API here: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/hooks

rwilliams
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 16, 2019

Great thanks, is there some documentation relevant to "build status created" and "build status updated" events? Looking for shape of the message that is pushed from the webhook build events.

I'm not the admin of the repo so I need more information before I can get what I need. Thanks!

seanaty
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 19, 2019 edited

Here is our documentation for this hook: https://confluence.atlassian.com/bitbucket/event-payloads-740262817.html#EventPayloads-Buildstatusupdated

And here is an example that I quickly tested out. It's an object with are repository, an actor, and a commit status object. The commit status object in turn has the info about the repository (again) and the specific commit, and the status of that commit.

 

{
"repository": {
"scm": "git",
"website": "",
"name": "test-repo",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/account-slug/test-repo"
},
"html": {
"href": "https://bitbucket.org/account-slug/test-repo"
},
"avatar": {
"href": "https://bytebucket.org/ravatar/%7B1ca93ec2-f356-461f-aedd-246c4e923c7d%7D?ts=1733796"
}
},
"full_name": "account-slug/test-repo",
"owner": {
"display_name": "MyNickName",
"uuid": "{504c3b62-8120-4f0c-a7bc-87800b9d6f70}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/%7B504c3b62-8120-4f0c-a7bc-87800b9d6f70%7D"
},
"html": {
"href": "https://bitbucket.org/%7B504c3b62-8120-4f0c-a7bc-87800b9d6f70%7D/"
},
"avatar": {
"href": "https://secure.gravatar.com/avatar/86509b1f8b92f157f1671d7a08e04ff5?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FA-2.png"
}
},
"nickname": "MyNickName",
"type": "user",
"account_id": "557058:7f21a3f9-5cd9-4b10-85ed-af9ebe8a2f0e"
},
"type": "repository",
"is_private": true,
"uuid": "{1ca93ec2-f356-461f-aedd-246c4e923c7d}"
},
"actor": {
"display_name": "MyNickName",
"uuid": "{504c3b62-8120-4f0c-a7bc-87800b9d6f70}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/%7B504c3b62-8120-4f0c-a7bc-87800b9d6f70%7D"
},
"html": {
"href": "https://bitbucket.org/%7B504c3b62-8120-4f0c-a7bc-87800b9d6f70%7D/"
},
"avatar": {
"href": "https://secure.gravatar.com/avatar/86509b1f8b92f157f1671d7a08e04ff5?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FA-2.png"
}
},
"nickname": "MyNickName",
"type": "user",
"account_id": "557058:7f21a3f9-5cd9-4b10-85ed-af9ebe8a2f0e"
},
"commit_status": {
"key": "1721615452",
"description": "",
"repository": {
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/account-slug/test-repo"
},
"html": {
"href": "https://bitbucket.org/account-slug/test-repo"
},
"avatar": {
"href": "https://bytebucket.org/ravatar/%7B1ca93ec2-f356-461f-aedd-246c4e923c7d%7D?ts=1733796"
}
},
"type": "repository",
"name": "test-repo",
"full_name": "account-slug/test-repo",
"uuid": "{1ca93ec2-f356-461f-aedd-246c4e923c7d}"
},
"url": "https://bitbucket.org/account-slug/test-repo/addon/pipelines/home#!/results/95",
"links": {
"commit": {
"href": "https://api.bitbucket.org/2.0/repositories/account-slug/test-repo/commit/01b20c98e100b62ce8993c117c3800c3d01a5446"
},
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/account-slug/test-repo/commit/01b20c98e100b62ce8993c117c3800c3d01a5446/statuses/build/1721615452"
}
},
"refname": null,
"state": "INPROGRESS",
"created_on": "2019-08-19T20:07:33.033470+00:00",
"commit": {
"hash": "01b20c98e100b62ce8993c117c3800c3d01a5446",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/account-slug/test-repo/commit/01b20c98e100b62ce8993c117c3800c3d01a5446"
},
"comments": {
"href": "https://api.bitbucket.org/2.0/repositories/account-slug/test-repo/commit/01b20c98e100b62ce8993c117c3800c3d01a5446/comments"
},
"patch": {
"href": "https://api.bitbucket.org/2.0/repositories/account-slug/test-repo/patch/01b20c98e100b62ce8993c117c3800c3d01a5446"
},
"html": {
"href": "https://bitbucket.org/account-slug/test-repo/commits/01b20c98e100b62ce8993c117c3800c3d01a5446"
},
"diff": {
"href": "https://api.bitbucket.org/2.0/repositories/account-slug/test-repo/diff/01b20c98e100b62ce8993c117c3800c3d01a5446"
},
"approve": {
"href": "https://api.bitbucket.org/2.0/repositories/account-slug/test-repo/commit/01b20c98e100b62ce8993c117c3800c3d01a5446/approve"
},
"statuses": {
"href": "https://api.bitbucket.org/2.0/repositories/account-slug/test-repo/commit/01b20c98e100b62ce8993c117c3800c3d01a5446/statuses"
}
},
"author": {
"raw": "Sean Conaty <sconaty@atlassian.com>",
"type": "author",
"user": {
"display_name": "MyNickName",
"uuid": "{504c3b62-8120-4f0c-a7bc-87800b9d6f70}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/%7B504c3b62-8120-4f0c-a7bc-87800b9d6f70%7D"
},
"html": {
"href": "https://bitbucket.org/%7B504c3b62-8120-4f0c-a7bc-87800b9d6f70%7D/"
},
"avatar": {
"href": "https://secure.gravatar.com/avatar/86509b1f8b92f157f1671d7a08e04ff5?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FA-2.png"
}
},
"nickname": "MyNickName",
"type": "user",
"account_id": "557058:7f21a3f9-5cd9-4b10-85ed-af9ebe8a2f0e"
}
},
"date": "2019-05-24T22:39:10+00:00",
"message": "test.csv edited online with Bitbucket",
"type": "commit"
},
"updated_on": "2019-08-19T20:07:33.033495+00:00",
"type": "build",
"name": "Pipeline #95 for random-failure"
}
}

 

seanaty
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 19, 2019

You can also get more information about the pipeline from the pipelines API. Unfortunately, that isn't included in the webhook, you'd have to query the pipelines API here: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pipelines/%7Bpipeline_uuid%7D using the build ID (instead of the pipeline UUID, as there is a 1:1 mapping between the 2).

You can get the build ID from the commit status URL that looks like this: 

https://bitbucket.org/account-slug/test-repo/addon/pipelines/home#!/results/95

In this example, the build ID is 95.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Upcoming Bitbucket Events