Run on Failure - how is this supposed to work

I am creating a deployment that calls other deployments… kind of a master/child situation.

In that deployment, I have a step after each child that will send an email if the previous step (deployment) fails.

I assumed that each email step (on failure) would only care about the previous step (deployment) only.

What appears to be happening is this:

If ANY of the deployments previous to the email step fails, all of the failure steps are triggered.

For example:

Child Deployment 1 fails.
Email (because of failure) is triggered
Child Deployment 2 SUCCEEDS
I would expect the email step to be skipped, but it’s not. It’s being triggered, I assume by failure of step 1.

How is this supposed to behave?

Hey @donald.long , thanks for reaching out!

What you’re seeing is the expected behavior - only run when previous steps fail is meant to act as a way to run steps when the process fails, and isn’t tied to specific steps. There are a couple of options you can look at to try and get the behavior you’re looking for, but can you tell me a little about your requirements first?

  • Are you hoping to get emails any time these projects fail to deploy, or only from your orchestration deployment project?
  • What step are you using to call your child deployment projects? The two most common steps are the built in Deploy a Release step or the Deploy Child Octopus Deploy Project community step. This will help determine the best way to get the data you need.

I am running many child deployments as Deploy a Release. directly afterwards, I have an email step that I want to have fire off ONLY if the PRECEDING deploy step fails… so that way if 2 out of 20 child deployments fail, I get emails on the 2 that fail.

Thank you for confirming -

There are two potential solutions that should help you get email notifications whenever a child deployment fails.

The first option which would allow you to keep your current project structure is to make use of variable run conditions. For example, if you had the following steps in your project:

  1. Deploy Child Project 1
  2. Email notification - Project 1
  3. Deploy Child Project 2
  4. Email notification - Project 2

You could use run conditions in steps 2 and 4 to only run when a specific step fails. Whenever a step runs in Octopus deploy, it generates a step specific variable in the process to track the status code of the completed step.

Using the example above, I could set the run condition for step 2 to:

#{if Octopus.Action[Deploy Child Project 1].Status.Code == "Failed"}True#{/if}

When deploying, Octopus will only run step 2 if step 1 registered as a failure. You can then create similar run conditions (replacing Deploy Child Project 1 with the relevant step name) and your emails will be tied to the failure of a specific step rather than the failure of any step within the project.

Another option would be to move your email alerts into the child deployment process - this way, you’ll get the notification from the child project itself instead of getting the multiple emails from the orchestration process.

Hopefully one of those is a viable solution for you and can get you moving in the right direction - if you have any questions or issues, feel free to reach out and I’m happy to help however I can.

Thanks Cory!