Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How do you capture a task error during a build?

If a task that is executed as part of a build gets an error, like trying to delete a directory that doesn't exist, how do you capture that error so the build will also fail? Currently, any inline script commands that execute as part of task do not cause the build to fail even when the command gets an error. I am guessing that the script is currently returning a "zero" return code as long as it executes despite whether or not it fails. If this is the case, I could use an example of how to return a "non-zero" return code from an inline script task. Is there any documentation available about handling errors in build job tasks?

1 answer

1 accepted

2 votes
Answer accepted

Hi @tclements

The script is returning the same error code that a bash script would return (I'm assuming you are using a Linux script). By default, a script will only return the error code of the last line run. In bash for example if you want to change this behavior you need to add the following line at the beginning of your script:

set -e

A different user was facing a similar issue in this question:

Please let me know if that fixes the issue.

Hi @Daniel Santos ,

Thanks for the response. I am using a script task but using "cmd.exe" as the interpreter. I didn't realize that the script will only return the error code of the last line run so that helps. I was able to get it working by exiting the script with the built in %ERRORLEVEL% parameter.

echo "Exiting with return code: " %ERRORLEVEL%
exit %ERRORLEVEL%

It would be handy to have the script stop after any failed commands. Instead of having to check "%ERRORLEVEL%" before every command, is there a "cmd.exe" setting similar to your bash "set -e" example that would stop the script on a failed command?

Hi @tclements

I'm not an expert on Windows scripting, but I was able to find an article that will probably help you. 

It does say that windows don't have an option similar to set -e.

I hope that helps.

Like tclements likes this

Hi @Daniel Santos 

That helps. We will check the %ERRORLEVEL% parameter after each command and exit with that parameter so that any windows script failed commands will return the appropriate exit code to stop the bamboo build and/or deploy.

Awesome! I'm glad that helped =]

Jimmy Seddon Community Leader Dec 06, 2019

Hi @tclements,

Just going to offer this as another suggestion (we are also a Microsoft shop) we converted a number of our scripts to PowerShell which made capturing/surfacing errors to the root of the script execution much easier.

Not sure if that is an option for you, but thought I'd suggest it as it made our lives easier.

-Jimmy

Like # people like this

That is a great suggestion too.
Than you very much for adding that here @Jimmy Seddon! =]

Like # people like this

Hi @Jimmy Seddon ,

Yes, we have a mixture of windows scripts and PowerShell scripts and are starting to find the benefits of using PowerShell as well.

Thank you for the suggestion!

Like Daniel Santos likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bamboo

Bamboo 101 Video

G’day Community! As we gear up to introduce Bamboo Data Center to the world, we wanted to make sure that we shared a bit more about Bamboo, the product. Our team has put together an overview video ...

215 views 4 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you