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} — <strong>#{step.Status.Code}</strong>
— #{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
- Deploy Database 1 — Succeeded — 00:00:07.4621818
- Deploy Database 2 — Skipped — #{Octopus.Action[#{step}].Output.StepDuration}
- Email Step Status — Running — #{Octopus.Action[#{step}].Output.StepDuration}
- Acquire Packages — Succeeded #{Octopus.Action[#{step}].Output.StepDuration}
- Apply Tentacle Retention Policy — Succeeded #{Octopus.Action[#{step}].Output.StepDuration}
I’m looking for this though
Task summary
- Deploy Database 1 — Succeeded — 00:00:07.4621818
- Deploy Database 2 — Skipped
- Email Step Status — Running
- Acquire Packages — Succeeded
- Apply Tentacle Retention Policy — Succeeded
Thanks