Can you include an Output variable in an email step?

I need to include an output variable from a previous step in an email, but it does not seem to work.

Here’s what I’m trying to do - pick up the output variable WorkItems from step Query Work Item.

#{OctopusParameters[“Octopus.Action[Query Work Items].Output.WorkItems”]}

When I query this using powershell in another step it works fine:

$Result = $OctopusParameters[“Octopus.Action[Query Work Items].Output.WorkItems”]

Am I missing something? How do I get more custom information inside my email?



Hi Dave,

Thanks for getting in touch! You can use them, but there is a catch. When you create an Octopus Variable during a step, the output is saved against the machine that created it.
Generally during a deployment all the steps will run on the same machines and you can just use those variables on the next step without referencing them.
However email steps are technically done on the Octopus Server machine, so when you call out your values in an email step you have to add:
$Result = $OctopusParameters["Octopus.Action[Query Work Items].Output[machine name].WorkItems"]

It is explained a little in this blog post: (see scoping and indexing output variables)

Hope that helps!

Thanks Vanessa – I can get that to work from Powershell, but I just can’t seem to find any example of the syntax to do this in the Email Step. Can you show me how to do the equivalent of this in the Email Step:

PowerShell (works):

$OctopusParameters[“Octopus.Action[Query Work Items].Output[RealMachineName].WorkItems”]

Email step:


Tried the following:

#{Octopus.Parameters[“Octopus.Action[Query Work Items].Output[RealMachineName].WorkItems”]}

#{OctopusParameters[“Octopus.Action[Query Work Items].Output[RealMachineName].WorkItems”]}

But it simply prints that line out. Can you run this in the email step and provide syntax please?



Hi Dave,

It should just be: #{Octopus.Action[Query Work Items].Output[RealMachineName].WorkItems}
The OctopusParameters part is just for within PowerShell. For use everywhere else the above syntax is what is correct.


That was it – thanks!


I know it’s been a while since this thread was last posted on, but i’m trying to do the exact same thing as Dave, but with no luck.

I’m using v2.5.10.567. Has there been any change to how output variables work? Do I need to define the variable manually first on the Variables tab or does the variable get added to the dictionary by Set-OctopusVariable?


I think I figured out the problem :frowning:

I was trying to send an email on a failure condition in the powershell script, and then take the failure result and put it into an email.

However, it seems that the output variables are not saved if the deployment step fails. Can someone confirm if that is the case? If so, is there any way around it??

Many thanks,

Hi Michael,

Sorry for the delay in getting back to you. Hopefully I understand this correctly.
If you use Powershell to set an octopus variable it is: a) only available from that point on in its own deployment
b) is not saved nor does it overwrite an existing project variable.

To understand the Octopus variables a bit more: We snap shot each variable when a release is created. These are the only variables a deployment has access to. There is no way to change this after a release is created nor update it from a deployment, as it needs to be the same for the next deployment or environment (if they share scope).

Could you explain what you are specifically trying to do so I can maybe help with an out of the box solution.


Hey Vanessa,

Thanks for the reply.

So what I am trying to do as part of the release process is to run a small powershell script to check the contents of a file. It reads the contents of the file into a variable (it is only a small file). If the validation of this file fails, the powershell script fails, and the next step would be to send a failure email. I want to use the variable created by the powershell script to put the contents of the file into the email. However, the variable never exists after the powershell script step fails.

If the powershell script passes (i.e. the validation of the file passes), then a different email is sent to different recipients. This email also uses the variable created by the powershell script, and I can use it without any problems.

So it seems to me, since the exact same script is being used prior to both possible emails, that the only difference is the failure of the step. This led me to think that the variables of a powershell script step are only saved fully if the step does NOT fail.

Is that the case?? Is there any way around this?

Many thanks,

Hi Michael,

Yeah you are right in your assumptions. When the step fails, it stops anything further on that step, and we make the variables available at the very end of each step. So it isn’t completed when it fails.
Can you get the variable out of the file in it’s own step, or is it integral and/or changed during the failing step?


Within an email template, how to iterate through multiple ‘RealMachineNames’ using {if} {/if}, so that the variable value is displayed within the email correctly no matter which machine it came from?
#{Octopus.Action[Query Work Items].Output[RealMachineName].WorkItems}

Basically - we have multiple machines to install to (QA, DEV, etc…) - how can the contents of a powershell script variable flow into all ‘Send emails’ appropriately?

Hi Sean,

Currently you can only define it with the step name and the machine name. Also currently you cannot define a varaible in a variable in email steps.
At some point in 3.x we are going to add a wild card to both action and output so you will get a result. You will have to assume they would always return the same value otherwise it won’t be safe to use.
We are also going to to look at expanding it so you could add a variable for the action step name or machine name to also make it more dynamic.

But right now, you only have the ability to hard code it. You can however wrap all the code in an if environment tag and display the parts with the hard coded machine and step names inside.


Can you provide an example to “code in an if environment tag and display the parts with the hard coded machine and step names inside”? I have tried, and not found success.


Hi Sean,

So if you create a variable in your project variables such as IsProduction and set the value as true and scope it to production you can then do the following in your email:

#{if IsProduction}
*production magic happens here*

Thus you would be able to add sections that have set machine names for those areas and they won’t show up unless on the correct environment.


Where does the ‘RealMachineName’ come from? I have tried the computer name listed for the tentacle (which is really an alias for the box) and the name set in windows and cant seem to get things working.

Hi Tim,

It is whatever the display name is for the machine. (When you click through to the machine the first field called display name).


Hi Vanessa,

Is there any expanded documentation on the syntax for the email template #{if IsProduction}?

For example #{if Environment = Production} ?

Hi Nick,

Here is the only documentation that we have on the variable syntax:


Using email in conjuction with storing output per step and machine name is hopeless.

Originally i used Octopus.Deployment.SpecificMachines in the email to show to which machines where targeted but that gave an output like machines-33, machines-65 and is of absoultely no use.

So Im trying to store the machines names for deployment made, only problem is since output is stored in dictionary where machine name is key, I need to set an output variable to true if deployments was made, then check all machine names to know which were deployed to, how to do that in an email? Well it seems the wrong approach, how about if #{Octopus.Deployment.SpecificMachines} could return the same values as the ones input by cmd line when executing deployment to specific machine, NAMELY THE REAL MACHINE NAMES!!!

Totally agree with Jonas here. I have the same issue and expected to find a way to get the machine names in an email without having to hard code it.
I have not figured out a way to do this, so it would be nice if you could provide some kind of work around (that does not involve hard coding names)

-Gard Ellefsen