Listing machines deploying to in an email

Hi. I’d like to get an email notification out of a deployment as it starts. The first thing a process will do is tun an email step that will provide some details including a list of all of the machines it will be deploying to. However I’m struggling to do this. Is this even possible?

I’ve tried doing:

#{each machine in Octopus.Deployment.SpecificMachines}
#{machine}
#{/each}

but to no avail.

Oh, and just to mention, there could be multiple steps in a process deploying packages to multiple roles. I can output machines when using the Octopus.Environment.MachinesInRole[role] variable, but I don’t want to hardcode roles, there number of roles may vary, and I’d like to to output the actual machine name that we see in the environments page, not something like machine-123.

Ah. #{Octopus.Deployment.Machines} nearly does it!

It lists all the machines but in the format of “Machines-123,Machines-456”

Is there a way to resolve this to the actual display name…?

Done it! Though someone please let me know if there is a simpler way :slight_smile: I’ve essentially created a powershell script template that calls the API using a read only APIKey. It then gets the machines names and puts them into an output variable. The next step in the process is the email template. this can then use the output variable created from the previous step.

Here’s my draft of the script template so far (named “Capture_Machines”):

Add-Type -Path 'C:\Program Files\Octopus Deploy\Octopus\Octopus.Client.dll'

$URL = '#{serverURL}'
$APIKey = '#{APIKey}'
$projectId = '#{Octopus.Project.Id}'
$envId = '#{Octopus.Environment.Id}'

$endpoint = new-object Octopus.Client.OctopusServerEndpoint "$($URL)","$($APIKey)"
$repository = new-object Octopus.Client.OctopusRepository $endpoint 

$machines = $repository.machines.FindAll()
$project = $repository.Projects.findone({param($d) $d.Id -eq $ProjectID})
$roles = $repository.DeploymentProcesses.Get($project.DeploymentProcessId).steps.properties.values.value -split ","

foreach ($role in $Roles) {
    if ($machineNames -eq $null) {$delim = ''}
    else {$delim = ', '}
    [string]$machineNames = $machineNames + $delim + ($machines | Where-Object {$_.Roles -contains $role -and $_.EnvironmentIds -contains "$envId"}).name
}

Set-OctopusVariable -name TargetMachines -value $machineNames

Then in the email I can refer to:
’#{Octopus.Action[Capture_Machines].Output.TargetMachines}

Seems to have done the job.