How do I add the job status (success or failure) in the email notification?

1.7k views Asked by At

I want to add the job status in the subject line of the email notification of Octopus Deploy. Can you please tell me the system variable to use or another way to add the status?

3

There are 3 answers

3
gvee On

Tracking deployment status

During deployment, Octopus provides variables describing the status of each step.

Where S is the step name, Octopus will set:

  • Octopus.Step[S].Status.Code
  • Octopus.Step[S].Status.Error
  • Octopus.Step[S].Status.ErrorDetail

Status codes include Pending, Skipped, Abandoned, Cancelled, Running, Succeeded and Failed.

Source: http://docs.octopusdeploy.com/display/OD/System+variables#Systemvariables-DeploymentStatusTrackingdeploymentstatus

So to apply this to your email subject (assuming you're using the inbuilt Send Email step:

Send Email Step

FYI: the box circled allows you quick access to the variables list.

You probably want to tweak the value to be closer to this, though

Deployment Status = #{Octopus.Step[Other Step Name].Status.Code}

As an extension to this answer; you can iterate over all steps and output their status, I guess.

Syntax here: http://docs.octopusdeploy.com/display/OD/Variable+Substitution+Syntax#VariableSubstitutionSyntax-Repetition (look for the Repetition heading)

Write-Host "Deployment Steps:"
#{each step in Octopus.Step}
    Write-Host "- StepName=#{step}; Status=#{step.Status.Code};"
#{/each}

Example output

Deployment Steps:

  • StepName=FirstStep; Status=Succeeded;

  • StepName=ThisStep; Status=Running;

  • StepName=YetToBeRun; Status=Pending;

0
JuztBe On

You could use variable expressions and deployment error variable to achieve this in email subject field. For example:

State of deployment: #{unless Octopus.Deployment.Error}Success#{/unless} #{if Octopus.Deployment.Error}Failure#{/if}
0
Daniel Brixen On

As a work-around you could use two steps for sending the 'status-email':

  1. One step sending 'success'-email. This step should have its 'Run condition' set to 'Success: only run when previous steps are successfull'.
  2. Another step sending 'failure'-email. This step should have 'Run condition' set to 'Failure: only run when a previous step failed'.

Perhaps the system-variables Octopus.Deployment.Error Octopus.Deployment.ErrorDetail could also be helpfull.enter image description here