Hello,
I want to include a script with an IF condition, depending on the outcome of the task that comes before it.
I have a JUnit Parser task which will either fail or succeed. I would like to catch the result and have different outcomes, like so:
IF 'PREVIOUS_TASK' = success:
DO A
IF 'PREVIOUS_TASK' = fail:
DO B
Now I am not sure how to catch the result of the previous task and have it evaluate against the if statement.
EDIT: Ideally, is there a way to check a task fail/succeed, without querying the API?
simple 02-Aug-2023 09:55:00 Finished task 'Parse Test Results' with result: Failed
Thanks!
#!/usr/bin/env bash
## bamboo does not catch some script failures unless this flag is set
set -e
TASK="CHECK BUILD STATUS"
echo ================== START $TASK ==================
## bamboo_jobFailed is a boolean
BUILD_STATUS=${bamboo_jobFailed}
echo "BUILD_STATUS_failed?: $BUILD_STATUS"
text=$"@here Hi all! There will be a delay in the Superset data refresh today, we are looking into it :slightly_smiling_face: Thank you!"
if [[ "$BUILD_STATUS" == "false" ]]
then
echo "the build is passing"
else
echo "the build has failed"
curl -X POST -H 'Content-type: application/json' --data "{\"text\" : \"$text\"}" https://hooks.slack.com/services/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
fi
echo =================== END $TASK ===================
Hello @Adrian Raszkiewicz,
Welcome to Atlassian Community!
You can have your task run based on a condition that checks for a variable. You need to add an Inject Variables Task to your plan that would consume a properties file. Hence, once the variable(s) are set, you can enable the condition on the task so it knows if it should run or not.
Kind regards,
Eduardo Alvarenga
Atlassian Support APAC
--please don't forget to Accept the answer if the reply is helpful--
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Eduardo!
Appreciate the steps, the previous task I have is a 'JUnit Parser' task so not entirely sure how I could have that always succeed?
Also, how could I have a task create a properties file with a set of key=value lines. saving either a success/fail variable from previous job? I assume I would need to check if job successful = assign variable. Which is what I am trying to do in the conditional?
Basically I have a script task running 'Python Unit Tests', which succeeds(technically), but than fails on the 'JUnit Parse' task when at least 1 test has failed.
Perhaps I could check for the 'Python Unit Tests' component, and then have my conditional task ran before the JUnit Parser? Or if there is a way to force the JUnit Parser into success to do it the way described.
**I basically want to send a custom slack message only if my tests fail. I tried the using the Notification option which works well if the plan has failed - but I am in need of a more customisable message.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Adrian Raszkiewicz,
The JUnit Parser task in Bamboo will not allow you to control or wrap its output or exit code. If you want that level of control, you'd have to run your JUnit tests from the command line in a Script Task, or even Maven or Gradle script if you wish.
Check this page for ideas on how to run the tests:
Best regards,
Eduardo Alvarenga
Atlassian Support APAC
--please don't forget to Accept the answer if the reply is helpful--
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.