Hello,
Is there a way to know inside a pipeline script, if the last pipeline for this branch was a success?
Thanks
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
By the docs the suggested command is triggering new pipeline. What I am missing?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"}}}]}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello
When I run this:
curl -X GET -is -u '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'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.