Dynamic email based on step status

#1

I currently have a project with steps in powershell that in addition to the work they do they also calculate the duration of the step. The step will then set an output variable with the duration. The last step in the project sends an email that can display the duration of the individual steps. However, its not a clean as I’d like it to be as there’s certain steps where this variable isn’t set like the email step itself or applying retention policy. Additionally if a step is skipped the duration variable is not set. When its not set it displays the variable name. I’d like it so that the duration is only displayed if the value is set, but I’m struggling with this little piece.

So as noted the steps calculate the duration and set this output variable

{Octopus.Action[#{step}].Output.StepDuration}

The email uses the standard dynamic ordered list but also appends the duration

<h3>Task summary</h3>
<ol>
#{each step in Octopus.Step}
  #{if step.Status.Code}
    <li>#{step | HtmlEscape} &mdash; <strong>#{step.Status.Code}</strong>  
	  &mdash; #{Octopus.Action[#{step}].Output.StepDuration}
    #{if step.Status.Error}
      <pre>#{step.Status.Error | HtmlEscape}</pre>
      <pre>#{step.Status.ErrorDetail | HtmlEscape}</pre>
    #{/if}  
    </li>
  #{/if}

The email output ends up something like this

Task summary

  1. Deploy Database 1 — Succeeded — 00:00:07.4621818
  2. Deploy Database 2 — Skipped — #{Octopus.Action[#{step}].Output.StepDuration}
  3. Email Step Status — Running — #{Octopus.Action[#{step}].Output.StepDuration}
  4. Acquire Packages — Succeeded #{Octopus.Action[#{step}].Output.StepDuration}
  5. Apply Tentacle Retention Policy — Succeeded #{Octopus.Action[#{step}].Output.StepDuration}

I’m looking for this though

Task summary

  1. Deploy Database 1 — Succeeded — 00:00:07.4621818
  2. Deploy Database 2 — Skipped
  3. Email Step Status — Running
  4. Acquire Packages — Succeeded
  5. Apply Tentacle Retention Policy — Succeeded

Thanks

(Kenneth Bates) #3

Hi,

Thanks for getting in touch! I suspect you can get the outcome you’re after by wrapping this StepDuration variable within another if statement to test if this variable exists per step. Something like the following:

<h3>Task summary</h3>
<ol>
#{each step in Octopus.Step}
  #{if step.Status.Code}
    <li>#{step | HtmlEscape} &mdash; <strong>#{step.Status.Code}</strong> 
	  #{if Octopus.Action[#{step}].Output.StepDuration} &mdash; #{Octopus.Action[#{step}].Output.StepDuration}#{/if}
    #{if step.Status.Error}
      <pre>#{step.Status.Error | HtmlEscape}</pre>
      <pre>#{step.Status.ErrorDetail | HtmlEscape}</pre>
    #{/if}  
    </li>
  #{/if}

Does something like this give you the result you’re looking for? Let me know how you go or if you have any further questions!

Best regards,

Kenny

#4

Thanks Kenny. That did the trick. I appreciate the help.

(Kenneth Bates) #5

Hi,

You’re very welcome! Great to hear that helped out. :slight_smile:

Don’t hesitate to reach out if you have any questions or concerns in the future!

Best regards,

Kenny

(system) closed #6

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.