Get machine proxy host in deployment setp

Good morning,

I’m wondering if it is possible to get the host of the machine proxy that is being used during a deployment step?

The only mention of proxy on the System Variables page is in relation to Octopus server, but I’m hoping it can be found somehow.


Hi @dgard1981,

Thank you for contacting Octopus Support.

For the Machine Proxies section in Infrastructure, there is not a built-in way to do this as there aren’t any internal variables I’m aware of that you can leverage to pull this information. However, I was able to come up with a simple PowerShell script that might work as a starting point for you:

$ErrorActionPreference = "Stop";

# Define working variables
$octopusURL = "YOUR_OCTOPUS_URL" # do not include a trailing slash /
$header = @{ "X-Octopus-ApiKey" = $octopusAPIKey }
$machineId = "Machines-XXX" # You may replace with $OctopusParameters["Octopus.Machine.Id"] if using inside Octopus

# Get Space ID
$space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/machines/$machineId" -Headers $header) | Where-Object {$_.Id -eq $machineId}

# Get machine list
$machine = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.SpaceId)/machines/$machineId" -Headers $header)

# Get Proxy Details
$Proxy = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.SpaceId)/Proxies/$($machine.Endpoint.ProxyId)" -Headers $header)

$machineProxyName = "$($Proxy.Name)"
$machineProxyHost = "$($Proxy.Host)"

write-host $machineProxyName
write-host $machineProxyHost

Let me know if that’s along the lines of what you were looking for at your earliest convenience.

Best Regards,
Donny Bell

Hi Donny,

Thanks for your reply.

I literally have a one line script that updates a DNS record for the proxy host, so I’m not too keen to script a solution to pull out that value, especially as I’d have to manage variables for the Octopus API and create an API key.

I can always add a variable that contains the proxy host value, so it’s not big problem, it just would have been nice if that value was available through system variables.