Octopus.Deployment.SpecificMachines only provides the octopus Id of a machine not it's real name

Hello,

I’ve an email step at the start of deployment that emails people that a deployment is about to happen. We currently have a very flaky machine that keeps dissapperaing off the network and whilst it is gone we are deploying only to the rest of the machines. I’m trying to add the ability to indicate which machines a specific deployment is going to and I know the Octopus.Deployment.SpecificMachines variable exists but it only contains the octopus id of the machine(s) (e.g machine-12) rather than the real/user friendly name of the machine (e.g. DEVDEPLOYSERVER1).

My question is, is there any way to convert the machine-id to the real name for an email step?

So I can basically have

Deploying to Servers

DEVDEPLOYSERVER1
DEVDEPLOYSERVER2

in the email.

currently, my email template for this is:

#{if Octopus.Deployment.SpecificMachines}

Deploying to Servers: #{each machine in Octopus.Deployment.SpecificMachines} #{machine}
#{/each}

cheers,

Huw

Hi Huw,

Thanks for getting in touch! I have added this to UserVoice at the following location:


It’s a great suggestion and really makes sense in the context that you need it.
We are adding a variable for Octopus.Machine.Name however you won’t be able to retrieve it in the context you need.

Thanks for the suggestion!
Vanessa

Right on the spot, this Octopus.Deployment.SpecificMachines is useless right now and does not comply with calling octo.exe -deployTo … -specificmachines “DEVDEPLOYSERVER1, DEVDEPLOYSERVER2, etc” I think this is a bug.

Hi,

Thanks for the feedback. Please make sure to stop by the uservoice suggestion if you’d like to see this implemented in the future.

In the meantime, you could use the following snippet which uses the function Get-OctopusMachine from the module Octoposh to resolve the names of the machines based on variable Octopus.Deployment.SpecificMachines

$IDs = $OctopusParameters['Octopus.Deployment.SpecificMachines'].split(",")
$names = Get-OctopusMachine -resourceOnly | ?{$_.id -in $Ids} | select -expandproperty name
$names

You can then use the content of the variable $names to build the string that you’ll pass down to Octo.exe

Hope that helps

Dalmiro

For those still looking for help on this. I needed to include the machine names in an email going out. The following was setup as a script step called MachineNames that runs on the server. (The #r needs to reference your installation path on the Octopus server. You will also have to change the server and apiKey variables.)

#r "d:\Octopus Deploy\Octopus\Octopus.Client.dll"

using Octopus.Client;
using Octopus.Client.Model;

var machineIds = Octopus.Parameters["Octopus.Deployment.SpecificMachines"];

if (!String.IsNullOrEmpty(machineIds))
{
    var ids = machineIds.Split(',').ToDictionary(m => m);
    var server = "http://octopus.server/";  
    var apiKey = "API-xyz";             
    var endpoint = new OctopusServerEndpoint(server, apiKey);
    var Repository = new OctopusRepository(endpoint);

    var ms = Repository.Machines.FindAll().Where(m => ids.ContainsKey(m.Id)).Select(m => m.Name);
    var machines = String.Join(", ", ms);
    Octopus.SetVariable("MachineNames", machines);
}
else
{
    Octopus.SetVariable("MachineNames", "All");
}

You can then reference the list of machine names in subsequent steps using the output variable.

#{Octopus.Action[MachineNames].Output.MachineNames}