Email not resolving variables

I’m using the email step, with some of the sample code in the documentation.

This code:

Deployment of #{Octopus.Project.Name} v#{Octopus.Release.Number} to #{Octopus.Machine.Name} in #{Octopus.Environment.Name}

Resolves to this:
Deployment of Guides Endpoint v1.11.5714.11973 to #{Octopus.Machine.Name} in Development

As you can see, there is one variable not populated. The other varibable (elsewhere in the email) that is not converting is #{Octopus.Tentacle.CurrentDeployment.TargetedRoles} (I’m trying to get the name of the server(s) it was attempting to deploy to (or which one it failed on).

Hi Jeff,

The reason the #{Octopus.Machine.Name} variable is not resolving is Email steps execute on the Octopus Deploy server; where this variable is not populated.

When you deploy, you are deploying to an environment, which may contain many machines. Package and script steps execute on each of these machines, and so have the #{Octopus.Machine.Name} variable available. But server-based steps (such as email steps), only execute once, on the server, where #{Octopus.Machine.Name} has no sensible value.

To achieve what you want, could you use #{Octopus.Environment.Name} instead? If your environments have meaningful names, this is often the appropriate value for a notification email.

Alternatively, you could populate an Output Variable in a previous step, and use it in your email step. Here is a thread which discusses this.

Regarding the other variable that is not resolving for you (#Octopus.Tentacle.CurrentDeployment.TargetedRoles}), it is the same situation.
There is an #{Octopus.Deployment.Machines} variable, which will contain a comma separated list of the machines included in the deployment.

You probably have already seen it, but just in case, this document provides a nice sample of an email template.

I hope this helps. If we can be of any further assistance, you know where to find us.

Regards,
Michael