I need to mark a step as failed when a command-line utility returns a certain exist code or console text.
I have everything working except for the part where I have to actually fail the step.
Any ideas?
– John Mills
Hi John,
Thanks for getting in touch!
I’m assuming you’re calling the command-line utility from a PowerShell script?
If so, you should be able to use the value in $LASTEXITCODE
to determine the exit code from the utility. Have a look at this StackOverflow post for some more info.
If the issue is simply failing the step, you can do that by using Exit 1
.
Hope that helps!
Damo
Thanks, but I’m already doing that.
What I need to do is Fail the Octopus Step when a certain $LastExitCode is returned or some specific console text is captured.
I have the last part already done. I just need to force Fail the Octopus step.
Hi John,
Apologies - I updated the answer after writing it originally so you wouldn’t have got the notification.
You can fail the step by using Exit 1
inside an if statement.
For example: if ($LASTEXITCODE -ne 0) { Exit 1 }
Thanks. Do different values provide other failure types?
e.g. Partially Complete, aborted, etc
Hi John,
No, the return value is just success or failure.
However, there are three statuses that can be returned, “Success”, “SuccessWithWarning”, and “Failed”. If you want to return SuccessWithWarning from your powershell script, you’ll need to write an error out, but still return a success value.
You can see this support question for more details, or just use something similar to the following:
Write-Error "Hello" -ErrorAction Continue
Damo