Email template - Deployment result (status) variable

Hi,

I think that the html email template on your site (http://docs.octopusdeploy.com/display/OD/Email+notifications) is a perfect start for an email. It sums up the deployment process and task summary. I’m only missing one thing, to put in the email-subject. The result of the deployment. This it fail or succeed? That’s the thing I want to now without even opening the email.

Which variable can I use?

Thanks,
Jorik

Hi Jorik,

Thanks for the kind words regarding our documentation.

There are two options, depending on which you prefer:

  1. We provide system-variables indicating the deployment status. You can make use of these within your template (including within the subject).

  2. You could create two email steps, one for success and one for failure. You can use the ‘Run Condition’ field of each step to ensure they only run on success or failure respectively.

I hope this helps,
Michael

Hi Michael,

  1. These variables are only on step/action level. And for the deployment as a whole there’s only Octopus.Deployment.Error? Because I’m looking for the result which is also in the icon on the site:
  • Green mark: succesfull
  • Green mark with warning: completed with warnings
  • Red: error
  • Black: cacncelled (I think this can never be in the mail as the mail is usually the last step, doesn’t matter)
  • Any other results?
  1. I thought of that, but I don’t like the fact that I need two steps for something so simple as a result of the deployment (just one variable where two emails differ). It also doesn’t giv

Thanks,
Jorik

If it’s the overall status you are interested in, and not individual steps, then the Octopus.Deployment.Error variable is the one to use. If it is empty, the deployment (to that point) was successful. If it is populated, then obviously there was an error.

The only thing that won’t give you is an ability to see if there were warnings. I don’t believe there is currently a variable you can use to access that information in an email template.

If there are events you are particularly interested in exposing to your email template, you can set output-variables as part of your deployment steps and access these from the email template.

I hope this helps,
Michael

Hi Michael,

Thanks. For the body-template it works, by using an if-statement with the Octopus.Deployment.Error variable.
However, I can’t us an if-statement in the subject…

Jorik,

Which version of Octopus are you using?
I believe you can use Octopus conditional-variable-syntax in the subject.
Did it not work for you?

Version 3.3.1

Could you send me an example so I’m sure I’m not making a mistake?

Thanks,
Jorik

Jorik,

My apologies for the delay.

I’ve just tested this:
#{if Octopus.Deployment.Error}Deployment Failed#{/if}#{unless}Octopus.Deployment.Error}Deployment Succeeded#{/unless}

It works as expected.

If you are still unable to get it working, you can paste in your subject expression and I’d be happy to take a look.

Regards,
Michael

Hi Michael,

If I put in above, the variables aren’t transformed.
This is the result in my email subject.
Deployment #{if Octopus.Deployment.Error}Deployment Failed#{/if}#{unless}Octopus.Deployment.Error}Deployment Succeeded#{/unless} - #{Octopus.Project.Name} #{Octopus.Release.Number} to #{Octopus.Environment.Name}

Without the if and unless statements, the transform worked:
Deployment of #{Octopus.Project.Name} #{Octopus.Release.Number} to #{Octopus.Environment.Name}

Any explenation for this?

Thnaks,
Jorik

Jorik,

It appears there was a typo in the expression I provided:
#{if Octopus.Deployment.Error}Deployment Failed#{/if}#{unless}Octopus.Deployment.Error}Deployment Succeeded#{/unless} - #{Octopus.Project.Name} #{Octopus.Release.Number} to #{Octopus.Environment.Name}

should be

#{if Octopus.Deployment.Error}Deployment Failed#{/if}#{unless Octopus.Deployment.Error}Deployment Succeeded#{/unless} - #{Octopus.Project.Name} #{Octopus.Release.Number} to #{Octopus.Environment.Name}

(extra } removed from unless opening tag)

I apologize for that. Does that help?

Had to look twice myself to see the missing bracket :wink:

That did the trick, thanks for your help!

You’re most welcome Jorik. I’m glad to hear it’s working.

Happy Deployments!

Hi Michael,

I have read through this thread, i have a question to add here, can we just send out a mail only when there is a deployment failure?

Regards
Mason

Hi Michael,
To add to my previous coment…
I tried working around with the run condition but there is a only one failure condition which just works only if a previous step failed.

Is there a way out where even a single step fails anywhere in the job and i get the email notification?

Regards,
Mason

Hi Michael,

The got the issue resolved, found the solution on one of your support pages.

Regards,
Mason

Hi Mason,
I’m glad to hear you were successful.

Happy Deployments!