Emailing machine names, and with only packages that get deployed

I have a setup in an Octopus project I’m testing, that will include the machine names in an email step.

Two questions about this:

  • What is a good way of using a foreach loop (using #{each action in Octopus.Action} or similar ), to loop through each process step that deploys a package, and printing the machine associated with this deployment step?
    I tried the method cwgy used in this thread, without success:
    Include targeted computers in email notification when deployment begins
    Should this work properly? We’re using v2018.08.11 here now.

  • How can I create this list, using only steps which had packages that were actually deployed?
    (guessing Powershell or Octopus variables would need to a new package relative to what’s on the tentacles)

This list is something our security team is looking for, and they want to ideally know only servers where files changed or were added.


Hi Jim,

Thanks for getting in touch! That solution provided by cwgy should still be working properly, though there may actually be a bit of an easier way and I’m interested in hearing if this helps in your scenario.

Using a couple of system variables, Octopus.Action.TargetRoles and scoping it to your package step, then using it in Octopus.Environment.MachinesInRole[_role_] with a result of #{Octopus.Environment.MachinesInRole[#{Octopus.Action[package_step_name].TargetRoles}]}", this will output the machine IDs of all machines in which the package step is deploying to.

I’m keen to hear what you think of this, and I’ll be more than happy to help arrive to a more suitable solution if this isn’t ideal. :slight_smile:

Best regards,


Hi Kenny,

I’ve had a bit of a challenge using variables very similar to what you mentioned there, and not sure why, however, I have one piece of what I need working, and have a couple followup questions for you if you’d be so kind!

In each process step, I have this script:
Set-OctopusVariable -name “EmailMachine” -value #{Octopus.Machine.Name}

In the email step, I have:
#{each action in Octopus.Action}

My questions on this, are:

  1. How can I check to see if a step, actually deploys a package? (not all do, and I want to check and only include machines for now, where a package is involved)
  2. How can I check to see if a package will actually be deployed? (it would by either the first deployment of a package, or a newer version than what’s currently on a tentacle)
    Looks like checking if Octopus.Action.Package.SkipIfAlreadyInstalled is false, might do this, but wanted to ask.
  3. Is there a way I can avoid needing code in each step, which sets this EmailMachine variable?
    I’d love to be able to, in the email step: loop through, check all steps with packages that are actually going to be deployed, and capture those target machines.


Hi Kenny (or another support person),

Any thoughts on this?

Hi Jim,

Thanks for following up, and I’m very sorry about the delay in getting back to you over the long weekend! Unfortunately there’s no system variable that exposes the step type (package, script, etc.), but I believe I have a workaround that may help, though it’s inconvenient as the lack of this system variable requires you to define output variables in individual steps.

This requires an output variable be created on at least every package step, with a name of something like StepType, and a value of Package Step. You can then iterate over steps in the last step of your process and print the variable value for each step. For example:

#{each action in Octopus.Action}
write-host "Step Type of #{Action.Name} is #{Octopus.Action[#{Action.Name}].Output.StepType}"

Does that help progress you to what you’re after?

It looks like you’re right on the money with the Octopus.Action.Package.SkipIfAlreadyInstalled variable as well. :slight_smile:

I hope this helps! Let me know how you go or if you have any further questions or concerns moving forward.

Best regards,


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