2

In one of my Octopus Deploy steps, I have a Powershell script called PostDeploy.ps1 that runs correctly, except that if it encounters an exception, the deployment continues as though it succeeded.

I've seen a few posts about the problems of powershell exit codes, but I can't find a solution for the particular problems of PostDeploy scripts.

How can I force a step to be marked as failed if PostDeploy encounters an error?

1
  • 1
    I've marked the answer by Alex M as correct because it addressed my question, but the actual cause of the issue was that PowerShell runs windows executables in a fire-and-forget fashion. To pick up failure, I had to add | Out-Host on the executable call, and then do an if-check on $LastExitCode -ne 0 Commented Apr 24, 2017 at 10:25

2 Answers 2

4

You should be able to fail with a combination of $LastExitCode is non-zero and Exit 1.

Couple googled up links:

P.S. I'm sure you aware, but just a reminder that a release in Octopus is snapshotting the version of variables, scripts, packages, etc. So would need to create a new release and/or packages.

Sign up to request clarification or add additional context in comments.

Comments

0

Sample Code

$exePath=$OctopusParameters["Octopus.Action[mydeploystep].Output.Package.InstallationDirectoryPath"] + "\myapp.exe"
& $exePath
if ($LASTEXITCODE -ne 0)
{
    EXIT 1
}

1 Comment

Octopus.Action[mydeploystep]. should be Octopus.ActionDeployStepName. or Octopus.Action[DeployStepName]. ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.