Exit 1 is not failing the deployment step

I can’t seem to get an powershell script step to stop the deployment. At first I thought it was because we were throwing an exception, and not exiting with 1. So I updated the script to write out the message, and exit 1, but this still doesn’t work:

if(!$success)
{
Write-Host “Verification failed - could not get appropriate response within timeout period.”
EXIT 1
}

I updated the process and re-created the release, I see the written message but the exit does not appear to work because it still considers the step as successful, hence the green outline:

Does anyone have any idea what I am missing?

Scouring the logs I’ve just spotted that it states that the exit code was 0.

Process C:\windows\system32\WindowsPowershell\v1.0\PowerShell.exe in C:\Octopus\Tentacle\Work\20200911101146-2699-137 exited with code 0

I’ve placed Exit 1 at the very top of the script, and it still does this. What am I missing?

Thanks in advance

Hi John,

Thanks for getting in touch!

It feels like in principal what you’re doing should work. I’ll spin up a test VM to look over this.

In the meantime, can you confirm what version of Octopus Server you are running?
EDIT: I’ve just seen that you posted in the Octopus Cloud section, so I assume you’re on the latest version :slight_smile:

Also, Calamari will check the $LastExitCode variable too, so it would be worth trying to insert your code directly into that.
e.g.

$LastExitCode = 1

You can also try the Fail-Step command detailed here.

Regards,
Paul

Thanks Paul,

I’ve updated the step to use Fail-Step, as that seems clear and obvious to me, however it still returns an error code of 0. I’ve double and triple checked I’ve updated all usages of that step, and recreated the release each time.

If I run the step directly outside of the deployment process it fails correctly, as you can see below:

To add a little more context, the step is running as a child step. I’d like to think that doesn’t matter, but you never know.

Child steps can cause weird outcomes, but I’ve done some (extremely basic) testing on this and it seems to be acting as expected.

I created this step template:

Added it as a child step:

And the result:

Mine is configured to run as a rolling deployment, with a window size of 1. Does that affect how your test behaves at all?

Mine had the same settings.

If you want I can log in to your cloud instance and take a look, see if anything obvious stands out. I’d just need the instance name/URL

Update for anyone stumbling on this in the future. This was a bug where by tasks running under an Azure target role weren’t failing when told to. It has been fixed and now works correctly.

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.