Hello all,
I have a Bamboo job that runs a Python script, followed by a PowerShell script. What I am trying to figure out, is if the python script throws an exception (like below), how can I make the bamboo job terminate so it does not run the PowerShell script? I tried passing sys.exit(1) but bamboo still reads it as 0.
build 03-Jan-2024 16:18:49 FAILED with the following error: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). in the file: Afilename.xlsx simple 03-Jan-2024 16:18:49 Finished task 'Run Python: CreateUploadForm' with result: Success
Thank you!
Billy
Hello Billy,
Welcome to Atlassian Community
If i understand correctly you have a single script task which contains Python and Powershell scripts.
You can try to use set -e at the beginning of the script task like below
#!/bin/bash
set -e
Bamboo will terminate the task when it sees any error and won't execute the next commands.
You can read similar information on this thread https://community.atlassian.com/t5/Bamboo-questions/Bamboo-does-not-respect-exit-status-of-docker-compose/qaq-p/1197430?utm_source=atlcomm&utm_medium=email&utm_campaign=kudos_answer&utm_content=topic
Regards,
Shashank Kumar
**please don't forget to Accept the answer if your query was answered**
Hello!
Thanks for the info.
Below is my current bamboo task list.
What I am looking to do is, if the script that runs python throws an exception, the powershell after it does not run.
According to bamboo, despite the exception being thrown, the script ran "successfully' and it continues running the powershell script.
I should mention that my bamboo servers are windows, not linux if that matters.
Where do I add the -e?
Is it here?
Thanks again!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Billy,
Thanks for providing the clarification regarding the structure of your Job, now my understanding is clear.
Basically you have 1 task which is Python script and if this Task fails, you don't want another Task which is Powershell script to be executed.
In your case somehow Bamboo is returning exit code as 0, hence marking your Python script task as success.
set -e option will not work here as it is for Linux and your scripts are getting executed in Powershell environment.
I am not an expert in Windows shell programming, you can try couple of Options.
Option 1:
You'll need to exit with the exit code if it's non zero manually, you can try something
if ($lastexitcode -ne 0) { exit $lastexitcode }
Option 2:
You can try the below
echo "Exiting with return code: " %ERRORLEVEL%
exit %ERRORLEVEL%
You can read more about these at
https://stackoverflow.com/questions/15777492/why-are-my-powershell-exit-codes-always-0
Regards,
Shashank Kumar
**please don't forget to Accept the answer if your query was answered**
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.