Missed Team ’24? Catch up on announcements here.

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

I would like a way to know the last status of a pipeline for specific branch

Ilan Hazan July 21, 2019

Hello,
Is there a way to know inside a pipeline script, if the last pipeline for this branch was a success?

Thanks

1 answer

1 accepted

0 votes
Answer accepted
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 21, 2019

Hello @Ilan Hazan,

I don't think there's any other way to get such information but making a REST API call. The /pipelines endpoint supports filtering by branch using target.branch query parameter, this endpoint is used by Pipelines UI.

For example, this returns a list of pipelines for branch master, for each pipeline there will be its target commit, selector and state (I decoded this URL to make it easier to read):

https://api.bitbucket.org/2.0/repositories/<workspace>/<repository>/pipelines/?fields=values.target.*,values.state.*,page,size&page=1&pagelen=10&sort=-created_on&target.branch=master

Note that first item will be the in-progress pipeline which is making the REST call.

If your repository is private you'll obviously need to make some additional configuration to make such REST API call from your pipeline.

Hope this helps.

Cheers,
Daniil

Ilan Hazan July 21, 2019

Many thanks @Daniil Penkin 

Ilan Hazan July 23, 2019

Hello,
By the docs the suggested command is triggering new pipeline. What I am missing?

Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 23, 2019

Hi @Ilan Hazan

I guess you're looking at the POST method for that endpoint – it indeed triggers a pipeline.

There's also a GET method (make sure you're on the right tab) which is used to find pipelines (browse history, essentially).

Cheers,
Daniil

Ilan Hazan July 23, 2019

I am doing the following and it is returning the last state of the pipeline. Because I am running it within a pipeline, the first result is the current pipeline. however because it is in progress it doesnt have "state.result".

curl -X GET -is -u user:pass 'https://api.bitbucket.org/2.0/repositories/
<workspace>/<repository>/pipelines/?sort=-created_on&target.branch=master&page=1&pagelen=2&fields=values.state.result.name'

 

Output:

HTTP/2 200

server: nginx

x-b3-parentspanid: 0000000000000000

x-cache: Miss from cloudfront

content-type: application/json; charset=utf-8

strict-transport-security: max-age=31536000; includeSubDomains; preload

date: Tue, 23 Jul 2019 15:21:04 GMT

x-served-by: app-146

x-b3-spanid: bea4c8b559014d7e

etag: "638e0d29661d0c702618b9dd635dc28b"

x-static-version: ff0d46ab6783

x-content-type-options: nosniff

x-credential-type: password

x-render-time: 0.742125034332

x-reads-before-write-from: default

x-request-count: 568

x-frame-options: SAMEORIGIN

x-version: ff0d46ab6783

content-length: 103

 

{"values": [{"state": {}}, {"state": {"result": {"name": "STOPPED"}}}]}

 

Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 23, 2019

The running pipeline indeed doesn't have state.result.name but it has other elements like state.name which indicate the state:

{
"values": [
{
"state": {
"name": "IN_PROGRESS",
"type": "pipeline_state_in_progress",
"stage": {
"name": "RUNNING",
"type": "pipeline_state_in_progress_running"
}
}
},
{
"state": {
"name": "COMPLETED",
"type": "pipeline_state_completed",
"result": {
"name": "SUCCESSFUL",
"type": "pipeline_state_completed_successful"
}
}
}
]
}

 This is what Bitbucket returns with fields=values.state.* query parameter.

Cheers,
Daniil

Abderrahim.Boussetta September 26, 2019


I got :

HTTP/2 404
server: nginx
cache-control: max-age=900
content-type: application/json; charset=utf-8
strict-transport-security: max-age=31536000; includeSubDomains; preload
date: Thu, 26 Sep 2019 16:04:24 GMT
x-served-by: app-143
x-static-version: ca263699922c
etag: "99914b932bd37a50b983c5e7c90ae93b"
x-render-time: 0.0196120738983
x-version: ca263699922c
x-frame-options: SAMEORIGIN
x-reads-before-write-from: default
x-request-count: 642
x-cache-info: caching
content-length: 2 {}


thanks
Rahim

Abderrahim.Boussetta September 26, 2019

can I get some help ?

Ilan Hazan September 29, 2019

You forgot the username / password?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events