Deployment Server Name Per Step?

Hi Octopus,

As part of a project, we’re obtaining deployment server names per project, using below API call:

Check what servers will be used for deployment…

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

$octopusURI = ‘https://octopusdev.xxxxxxxx.com’ # Your server address
$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI , $Key
$repository = New-Object Octopus.Client.OctopusRepository $endpoint

$machineIds = $OctopusParameters[‘Octopus.Deployment.Machines’].Split(’,’)
$tempArray = @()

$Servers = $machineids.Split(" ")

Foreach ($Server in $Servers)
{
$machine = $repository.Machines.Get($Server)
if($machine.Name.length -gt 7)
{
$tempArray += ‘"’+$machine.Name+’"’
}
}

$ofs = “,”
$ServerList = ‘[’+ [string]$tempArray+’]’

Is it possible to obtain server name(s) for each deployment step?

Many Thanks,

Richard

Hi Richard,

Thanks for getting in touch! You can certainly obtain all the machine names during the deployment. Depending on exactly what and when you require this information, an easier option may be to take advantage of a couple system variables that you could write out in a script. For example, you could use Octopus.Deployment.Machines for the ‘Ids of machines being targeted by the deployment’, or Octopus.Environment.MachinesInRole[RoleName] and specify the role(s) a specific step is scoped to to get all machines within that specific role.

Using the Octopus.Client.dll, we have a sample PowerShell script to list all machines in the deployment which may also help.

I hope this is helpful! Please don’t hesitate to reach out if you have any further questions or concerns moving forward. :slight_smile:

Best regards,

Kenny

Thanks Kenny!

Will give this a try and let you know for any issues…

Richard

Sorry Kenny, one further question.

Is it possible to obtain deployment targets roles for a specific step?

Many Thanks,

Richard

Hi Richard,

Thanks for following up, and no need to apologize for additional questions! :slight_smile:

You can certainly obtain the target roles in which a specific step is scoped to, and probably the easiest way would be to use the system variable Octopus.Action.TargetRoles (where you can specify the step name if needed) to retrieve the role name. For example, the following script step writes out the machines that exist in the role that my previous step (called Check health) is scoped to:

write-host #{Octopus.Environment.MachinesInRole[#{Octopus.Action[Check health].TargetRoles}]}

I hope this helps!

Best regards,

Kenny

Thanks so much Kenny, this is exactly what I was looking for! :grinning:

Have a great day,

Richard

Hi Richard,

That’s great to hear! You’re very welcome, and don’t hesitate to reach out if you have any further questions in the future. :slight_smile:

Best regards,

Kenny

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