Email template for actions within a step

I’d like to trim down my email templates to not include details about the skipped steps. Right now I am iterating through each action in the deployment process and I cannot figure out how to check that that parent step status was skipped or not.

I can check the status of each step’s status by iterating through the Octopus.Step list.

#{each step in Octopus.Step}
  #{if step.Status.Code != "Skipped"}

Similarly I can write out each action by iterating through the Octopus.Action list

#{each action in Octopus.Action}

But I’m not sure how to join them together. Maybe something like:

#{each step in Octopus.Step}
  #{if step.Status.Code != "Skipped"}
    #{each action in Octopus.Action[step.Name]}

I think I’m nearly there. Any help would be appreciated.

Hi Robert,
Since Octopus.Action[step.name] is already indexed you wont be able to do an each action in.. before it as per your example attempt.

Unfortunately we currently have no simple property mapping from Steps to Actions however there is the Number property. If you print this out you will see that the Steps will have numbers like 1, 2, 3, ... while the actions contained within then will be decimal delimited such as 1.1, 1.2, 1.3 ....
Using this knowledge and a bit of combined variable substitution/PowerShell scripting we should be able to get what you are after.

#{each action in Octopus.Action}
    $stepNumber = "#{action.Number}".Split(".")[0]
    #{each step in Octopus.Step}
        if("#{step.Number}" -eq $stepNumber -and "#{Step.Status.Code}" -ne "Skipped") {
            Write-Host #{action.Name} # "- Did Not Skip"
        }
    #{/each}
 #{/each}

Not pretty, bit it should do the job. Give the above a try (with a little tweak where necessary) and let me know how it goes.
Cheers,
Rob

The logic looks good, but it is being rendered as plain text in the success emails:

Deployment process

$stepNumber = “#{action.Number}”.Split(".")[0] if("#{step.Number}" -eq $stepNumber -and “Succeeded” -ne “Skipped”) {

  1. Deploy ABC website - ABC.Web version 4.1.5862.22554
    } if("#{step.Number}" -eq $stepNumber -and “Succeeded” -ne “Skipped”) {

I will try this and see what happens:

<h2>Deployment process</h2>
<ol>
#{each action in Octopus.Action}
  #{$stepNumber = "#{action.Number}".Split(".")[0]}
  #{each step in Octopus.Step}
    #{if("#{step.Number}" -eq $stepNumber -and "#{Step.Status.Code}" -ne "Skipped")}
      <li><strong>#{action.Name}</strong> #{if action.Package.NuGetPackageId}- #{action.Package.NuGetPackageId} <em>version #{action.Package.NuGetPackageVersion}#{/if}</em></li>
    #{/if}
  #{/each}
#{/each}
</ol>

Hi Robert,
Unfortunately I don’t think your pattern attempt is going to work either. Octostache is fairly simplistic in its functionality and only really does straightforward string replacements (with the exception of simple conditionals) and not string manipulation. The sample I provided also requires PowerShell to work which doesn’t get used during an email step (hence the text being printed is not being evaluated). I Think for this to work you need the OctoStache reference to the step name from the action. This is currently not supported but I have added Git Hub Issue #2302 to get this work done. Feel free to subscribe to this issue to keep track of its progress. I hope this is an acceptable solution until this ticket gets prioritised.
Thanks for the feedback on your requirements as it allows us to improve the product for everyone.
Robert

Okay - fair enough. It’s a nice to have feature.