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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,551,879
Community Members
 
Community Events
184
Community Groups

How to check for build failure within a running build?

Philip Colmer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 30, 2019

I'm working on a Bamboo plan that interacts with a Service Desk ticket. The idea is that Bamboo does some long-running work and then updates the ticket with the results.

The bit I'm trying to figure out at the moment is how to update the SD ticket if something goes wrong with the Bamboo build. I've added a script to the plan under the "Final tasks" section with the intention that the script would query Bamboo to find out the status of the running build and, if something has gone wrong, update the SD ticket with that information.

I'm querying /rest/api/latest/result/<plan key>/<build number> and getting the data back from Bamboo but "state" and "buildState" are both set to "Unknown".

I could implement a solution by creating a marker file at the start of the plan and deleting it after a successful run of the long-running script then have the "final task" script check for the existence of the marker file but it seems a bit inelegant.

Is there any method for me to retrieve the information I'm looking for?

 

1 answer

1 accepted

3 votes
Answer accepted
Daniel Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Jun 03, 2019

Hi @Philip Colmer

Thank you for clearly stating the problem, it helps a lot who answers.

The perfect solution for you would be using the Pre-Post Build Command Runner plugin. Unfortunately, It is not available for Bamboo versions after 6.7.3. It is an Atlassian Labs plugin and therefore has no support nor updates guaranteed, but there is a request to update it in our issue tracker [BAM-20454] Update Pre-post Build Command Runner for Bamboo 6.8+.

 

I'm querying /rest/api/latest/result/<plan key>/<build number> and getting the data back from Bamboo but "state" and "buildState" are both set to "Unknown".

The result "Unknown" is expected for the plan assuming the build is still running, which is the case when you call the REST API from your final stage. The requests that would give you some data would be to JOBs.

Assuming your last plan stage is a final stage and you want to check if the build succeeded, you just need to make sure that all jobs in the prior stage succeeded.

I was running some tests and this solution worked for me:

job1=`curl -u<USER>:<PASSWORD> -H 'Accept: application/json' \
-X GET "<BAMBOO_URL>/rest/api/latest/result/<PROJ-PLAN-JOB1>-KEY-${bamboo.buildNumber}?buildstate" \
| jq -r '.buildState'`

job2=`curl -u<USER>:<PASSWORD> -H 'Accept: application/json' \
-X GET "<BAMBOO_URL>/rest/api/latest/result/<PROJ-PLAN-JOB2>-${bamboo.buildNumber}?buildstate" \
| jq -r '.buildState'`

if [ $job1 == 'Successful' ] && [ $job2 == 'Successful' ]
then
echo '****Successful****'
else
echo '****Failure****'
fi

Please let me know if that helps you to move forward.

Philip Colmer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jun 04, 2019

Hi Daniel

That works perfectly. Thanks for the suggestion.

Regards

Philip

Would this work for plan branches?

Daniel Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 20, 2020

It should, but you need to make sure the proper job is used.
For the main plan it will be something like mentioned before:

<PROJ-PLAN-JOB1>

For a plan branch it should be like

<PROJ-PLAN0-JOB1>

each plan branch will have a different PROJ-PLAN"X" name.

You should be able to use a variable (from  Bamboo Variables)to build the job key.

I hope it helps.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events