According to http://docs.octopusdeploy.com/display/OD/System+variables I should be able to get the machine name of the deploy target using the variable Octopus.Machine.Hostname, but when we tried to use that variable in a deployment just now, it was empty.
Running the following script from the script console confirms that the variable does not return the same thing as
hostname (which is what it should do, according to the docs):
"Hostname: $(hostname)" | Out-Host
"Octopus: $($OctopusParameters["Octopus.Machine.Hostname"])" | Out-Host
We’re running Octopus 3.5.2 and the tentacles are version 3.5.2 with Calamari version 3.5.4.
What are we doing wrong?
Thanks for getting in touch. Unfortunately you aren’t doing anything wrong. Our documentation is wrong on this and I’ll fix it up. The
Octopus.Machine.Hostname variable is only set for Listening Tentacles and returns the host of the uri that was used to register the Tentacle. This could be an IP Address, a machine name or a URL.
As a workaround you can use a Run Script step to set the hostname to an Output Variable (see http://docs.octopusdeploy.com/display/OD/Output+variables and in particular https://octopus.com/blog/fun-with-output-variables) and then use that value in later steps. The Output Variable will be correctly scoped to each Machine as described in the linked blog post.
If you need help with this or have a use case this won’t cover please let me know.