Is there a way to know in a plan's final stage the build status?
Asked by yogev ch:

I want to perform some cleaning of an external resource, so I've created a stage, which is a final stage of a plan.  
According to Bamboo it should run no matter what.

Is there a way to know in that final stage, if all stages until that stage succeeded or at least one failed?


Answers:
author: Shashank Kumar
body: Hello Yogev,

Welcome to Atlassian community

You can look at the Buildresult of that run and see what stages passed and what failed, in this particular run, we can see Stage 2 Job 2 failed and Final stage was run successfully.

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/348866i72DAA8F36F46C579/image-size/large?v=v2&px=999 "image.png")

Regards,

Shashank Kumar

**\*\*please don't forget to Accept the answer if your query was answered\*\***

comments: author: yogev ch
body: Thanks for your response.

Maybe I didn't clarify myself: I meant that I want to check programmatically in a script task of the final stage, if the build failed or not.

I want to be able to perform some cleanups in case the build failed, automatically in a task within the final stage.


author: Shashank Kumar
body: Hello Yogev,

You can use the REST API to get the details, refer [api-api-latest-result-projectkey-buildkey-get](https://developer.atlassian.com/server/bamboo/rest/api-group-api/#api-api-latest-result-projectkey-buildkey-get) for more details.

You'll need to use the expand parameter for stages, see example below

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/348880iDEAE186E63506AB9/image-size/large?v=v2&px=999 "image.png")

The result would look something like below when you expand the stages, it would print the status of the stage and you can see if your previous stage was successful or failed.

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/348881iBF02240CD013D814/image-size/large?v=v2&px=999 "image.png")  
Regards,  
Shashank Kumar


author: yogev ch
body: Thank you  
Hmm, for some reason I get

```
curl: (56) Recv failure: Connection reset by peer
```

My request is

```
curl -X GET -H 'Authorization: Bearer Mddd' -H 'Accept: application/json' --url 'http://bamboo:8085/rest/api/latest/result/PPP-AO-123?expand=stages'
```


author: Shashank Kumar
body: Seems to be a network/Proxy/Firewall Issue, Have a read at at <https://github.com/curl/curl/issues/1016>

Regards,

Shashank Kumar


author: yogev ch
body: Thanks. I think it doesn't help though.

Because this one (without a build number) does work.

```
curl -X GET -H 'Authorization: Bearer Mddd' -H 'Accept: application/json' --url 'http://bamboo:8085/rest/api/latest/result/PPP-AO?expand=stages'
```

```
{
"results": {
"size": 25,
"start-index": 0,
"max-result": 25
},
"expand": "results",
"link": {
"href": "http://bamboo:8085/rest/api/latest/result/PPP-AO",
"rel": "self"
}
}
```


author: Shashank Kumar
body: Hello Yogev,

It won't work without the build number, because you are trying to fetch the results data which is available per build.

You can use **bamboo.buildNumber** variable to pass to the API, read [Bamboo variables](https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html) for more details

Regards,

Shashank Kumar


author: yogev ch
body: In my last response when I added the example

```
curl -X GET -H 'Authorization: Bearer Mddd' -H 'Accept: application/json' --url 'http://bamboo:8085/rest/api/latest/result/PPP-AO?expand=stages'
```

I meant to show that other requests does work.

Anyway... I restarted my computer and it now works, I have no idea how.  
Thank you!  

<br />