Deploy.ps1 exiting with non-0 error code causes deploy to continue

andrew's Avatar

andrew

12 Apr, 2017 01:33 PM

Hi,

I have a PowerShell Deploy.ps1 with the following at the end of a script:
if ($LastExitCode -ne 0) {
  $exitCode = $LastExitCode
  write-host "Install service returned $exitCode!" -BackgroundColor Red
  $host.SetShouldExit($exitCode)
}

The script fails and I get the error status, the script stops but the deployment continues as if the exit code was 0.

Any suggestions?
Thanks.
Andrew.

  1. Support Staff 1 Posted by Ilya Finkelshte... on 12 Apr, 2017 06:33 PM

    Ilya Finkelshteyn's Avatar

    Hi Andrew,

    Please try to replace $host.SetShouldExit($exitCode) with throw and let us know if this helps.

    Ilya.

  2. 2 Posted by andrew on 13 Apr, 2017 08:56 AM

    andrew's Avatar

    Hi,

    That did it. May be worth somewhere in the documentation as it is different from the way to get the build to fail if you have PowerShell in your build job.

    Thanks,
    Andrew.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac