Shell script step - output variable when script execution fails
long-term
N
Novel Cod
Scenario:
You want shell script step output a variable even when script execution fails. An example below.
I am checking if DNS name exists. If it doesn't exist I want to fail the step so I can do failure execution strategy of retry mark as success.
At same time I want output variable available so I can use the output variable in subsequent steps.
However afaik there is no way to do an output variable if you want to mark step as failure.
set +e
echo "DNS name to test: $dnsname"
host $dnsname
dnsteststatus=$?
echo "DNS test returned status: $dnsteststatus"
if [ "$dnsteststatus" -eq 0 ];
then
echo "DNS name for $dnsname was found in DNS"
else
echo "DNS name for $dnsname was not found in DNS"
fi
Ex script.
Log In
Rohan Gupta
Merged in a post:
Output variables to get processed in case the step fails and the value for the output variable is set
V
Verdant Jaguar
How can I retrieve an output variable from a failed task, which is being passed as an environment variable to a rollback step, considering that the variable is set before the task fails? The goal is to ensure that the variable, which is written and available prior to the failure, can still be accessed and used in subsequent steps, such as a rollback step, even though the task itself has failed.
Canny AI
Merged in a post:
Deploy stage command step, output variable from powershell for the next command to use
E
Ethical Grasshopper
Deploy stage command step, output variable from powershell for the next command to use.
A way to create output variables for different commands.
Canny AI
Merged in a post:
Can we print output variables when the powershell script fails in the inline model
P
Parental Platypus
Issue Description:
When step (shell script using inline PowerShell) the PowerShell script fails, the output variables declared in the script are not printed. However, in my scenario, I need the output variable value even if the script fails, as it is required for the next step or for the rollback step.
Canny AI
Merged in a post:
Allow publishing output variables even if the step fails
F
Fawn Limpet
Having output variables is useful for reporting purposes even if the step is failed. For example, I'm making some request to some URL, which fails, so I set the step as failed, but still want to have available that URL as an output variable instead of having to find it through the logs.
Rohan Gupta
long-term
Rohan Gupta
pending feedback
Are you trying to reference output variables in rollback? When you mark a step as failed, you are looking to parse a variable output to a subsequent step?
N
Novel Cod
Rohan Gupta:
"When you mark a step as failed, you are looking to parse a variable output to a subsequent step?"
Correct.
I want to parse the output variable even if step fails.
If that is difficult to achieve , next best alternative is to allow the step to succeed (which can be easily done via set +e inside the script).
But then, provide a failure type based on the output variable.
For instance if my output variable is var1, allow a failure type based on output variable from the step.
So it is easy to write, fail the step if expression var1 = something.
Screen shot attached. Basically allow a new failure type say "variable expression" .