I have a powershell script deployment step. In the script I’m calling an external command and I redirect the output into a variable:
$output = command 2>&1
So including StdError. I then want to look at the output and do different things depending on what it is.
Unfortunately if the command exits with a non 0 exit code the deployment always fails with “‘The remote script failed with exit code 1’.”
How do I prevent this from happening?
Does explicitly exiting your script with a 0 error code (ie
exit 0 at the end) help? By default PowerShell will store the result of your command in
$LASTEXITCODE and use that as the exit code of the whole script. Or it might be safer to set
$LASTEXITCODE = 0 after this command so you still catch later errors.
If that doesn’t do it can you let me know which version of Octopus you are using, we have changed how we handle errors in scripts slightly over the years.
I found a way to write my script without requiring a call to a command that potentially fails. I am on version 3.11.10