Deploy won't fail when Powershell script fails

I have a script i know is failing, i can see it in the log however no matter what i seem to do i can’t get it to cause the deployment to fail which is bad, if something goes wrong with the process you need to know about it.

i read this blog post and it seems like its an ongoing battle

My solution so far is to wrap my script in a Try Catch block, this at least catches any exceptions thrown by the script. In addition i need to read the standard error of a console app it executes and report back to powershell but i haven’t got that far yet.

My try catch looks like this
try
{
#stuff to execute console app
}
catch
{
“Failed to run script”
[Environment]::ExitCode = 1
$LastExitCode = 1
Exit 1
}
i can see that the catch is working because it echo’s “Failed to run script” but I’ve tried 3 different methods to try and return an error code but the deployment still passes. How do i manually fail the deployment from a powershell script?

Actually this was my mistake, I was trying to test the script by promoting an existing release but this seems to run a cached version of the script and not the latest. This works

try{
#stuff
}
catch [Exception]
{
"Failed to run package script: $.Exception.Message"
$
.Exception.StackTrace
Exit 1
}

Hi Ryan,

Thanks for the update and I’m glad you got it sorted!

Paul