How to send an email when deployment fails

So we have continuous deployment environment that deploys an MVC application and the database. Sometimes the database scripts fail and the deployment fails.

When this happens I would like to send an email to the team, so they can fix the corrupt script(s) (with the error log, or the link to the error log). How is this possible?
I have a mailing step at the end of the deployment, but when deployment fails this mailing step is not executed.

If you are using TC there is an option, provided you are using the octo plugin, that will wait for the deployment and fail the build if the deployment fails. Or send an email in your powershell script (DeployFailed.ps1).


In Octopus 2.0 you can add an email step that only runs on failure, or that always runs whether successful or not. The bottom of this page has an example:


Is there a variable that can be used to determine if previous step(s) have failed or if all have succeeded? We have a notification step and we want the message to conditionally say “completed successfully” or “failed”.

Right now we do this by running the same script, once if previous steps have failed, and once if they’ve succeeded. It would be nice to consolidate to one step that can inspect a variable to determine the result.

Hi Chris,

Currently there isn’t. We’ll add it in a future release.


It would be awesome if I could get an email with the error that occurred and maybe the last X number of messages. We use Octopus as a CI tool and I don’t like requiring people to login to Octopus to see why it failed.

Hi Paul,

Thanks for getting in touch! Please see the following documentation:

At the bottom it describes variables related to deployments status, errors and error codes. All can be used in email templates.

Hope this helps!

Hi Vanessa,
What I really need to see are the log details. The status, errors and
error codes tend to be very generic. Many of my steps write to the host in
the powershell so I need to see what those messages are. Is there a way to
capture that in the email easily?


Hi Paul,

I am very sorry about the delay in getting back to you about this issue. Your response was caught in the ticket spam for our forum, which I only discovered today.
The error is generic, but the error code will be more like "System.Net.SocketException: The server could not be contacted (at …)"
This is slightly more than generic, but there is no way that I am aware of to grab the logs and place them in an email.


Hi Venessa,

I have followed the thread, I have one thing to add here
I want to send the email with only the error messages like the one in the attached screenshot. Is it possible? are there any variables which might help?

I want only the error message to be sent,capture 2 gives the current form of error reporting.

We currently use this to get the error messages:

Task summary

    #{each step in Octopus.Step} #{if step.Status.Code}
  1. #{step | HtmlEscape} — #{step.Status.Code} #{if step.Status.Error}
    #{step.Status.Error | HtmlEscape}
    #{step.Status.ErrorDetail | HtmlEscape}
  2. #{/if} #{/each}


Hi Mason,

Thanks for getting in touch! No, unfortunately we do not capture any further error messages or details in variables at this time.
The ErrorDetail is the most information captured.


Thanks Venessa for getting in touch and answering the question.

I have one more question to add here, how do we send out an email on successful deployments of all projects to an environment.
Currently i only see it per project. Is there any variable which captures all the project statuses and sends out an email.

eg: Deployment of all projects done to PROD successsfully.

Thanks in advance.

Hi Mason,

Currently Octopus has no concept of knowing all projects to be able to send an email outside of a deployment. The only option is per project.
We do have something we are working on by way of triggers called Reactions:
You might be able to use this to trigger an event.

It might be best to write something to work with the API to send a summary email of the days deployments. Or add such a suggestion on our UserVoice site: