Can't seem to faiil a deployment step

Why do our failing steps always seem to show as green!

For instance in our database deployment deploy.ps1 we have this code…
@@@
if($builtAgainstVersion -ne $currentDbVersion)
{
Write-Error “Destination Database is not the expected version: Expected=$builtAgainstVersion , Actual=$currentDbVersion”
[Environment]::ExitCode = -1
$LastExitCode = -1
exit -1
}
@@@
As you can see nothing seems to work…
We still get this in our output…
@@@
2013-07-18 14:13:43 INFO [Deploy Script] ERROR: C:\Octopus\Applications\CS_Test\CentralServicesDB\1.2.0.105\Deploy.ps1 : Destination Database is not the expected
2013-07-18 14:13:43 INFO [Deploy Script] ERROR: version: Expected=1.2.0.93 , Actual=
2013-07-18 14:13:43 INFO [Deploy Script] ERROR: At C:\Octopus\Applications\CS_Test\CentralServicesDB\1.2.0.105\Bootstrap.6f649b87-e062-445a-b8d5-90391cc71302.ps1:342
2013-07-18 14:13:43 INFO [Deploy Script] ERROR: char:1
2013-07-18 14:13:43 INFO [Deploy Script] ERROR: + . "C:\Octopus\Applications\CS_Test\CentralServicesDB\1.2.0.105\Deploy.ps1"
2013-07-18 14:13:43 INFO [Deploy Script] ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2013-07-18 14:13:43 INFO [Deploy Script] ERROR: + CategoryInfo : NotSpecified: (:slight_smile: [Write-Error], WriteErrorException
2013-07-18 14:13:43 INFO [Deploy Script] ERROR: + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Deploy.ps1
2013-07-18 14:13:43 INFO [Deploy Script] ERROR:
2013-07-18 14:13:43 WARN [Deploy Script] The script returned an exit code of 0, but output was written to the error output stream. Please investigate any errors in the script output above.
@@@

This is an issue we’ve brushed under the carpet since we started using Octopus that we’d like to get to the bottom of. Any ideas?

TIA,
Graeme

Hi Graeme,

It’s a strange behavior of PowerShell. We set the error action to “stop”; so when you call “Write-Error”, nothing else gets executed - including your exit code statements.

You can try setting the exit code before calling Write-Error.

Paul

Cheers Paul,
I just wrapped everything in a Try/Catch and throw “message…” when my comparison fails and use a normal Write-Host and exit -1 and it’s working.

The Write-Error seems to be a bit messy anyway for our needs so, that’s fine.
Thanks Again,
Graeme.