Octopus.Machine.Hostname with Offline drops

We have some “substitute variable in steps” in our deployment process that relies on the Octopus.Machine.Hostname value to correctly transform certain files during deployment (some .js files).

It is working perfectly on “Listening tentacles” deployments, but when using it on an offline deployment, the “Octopus.Machine.Hostname” is not being replaced, thus, our production deployments (offline) could not be used transparently.

It would be nice if this could be allowed also for offline drops.

Hi Gabriel,

You’re right, that variable is only set for Listening Tentacles.

What you could do, to make your deployment process transparent, is to to add that variable to your project’s variables, and scope it to your offline target.

Please let me know if this helps?

Regards,
Michael

Hi Michael,
Thanks for the quick answer. I’m afraid that adding a variable and scoping it to the offline target will not make the process as transparent as we want. Our scenario is a production environment that could have many different servers with the same role (i.e.: application servers), and we need to put in certain files, the name of the machine. Scoping each of the production server as an offline drop is not an option (we don’t even know the server names and we don’t want to couple our package generation process with our customer, maybe dynamic, infrastructure)

Regards, Gabriel.

I understand.

In that case the only recommendation I can make is rather than using that variable, to retrieve the value in your scripts. For example:

[System.Net.Dns]::GetHostName()

or

$env:COMPUTERNAME

You could write your scripts such that they use the Octopus.Machine.Hostname variable if it is defined, otherwise use one of the options above.

Could this work for you?

No, it won’t work, because we are not using scripts for replacing the files, we are using “Substitute variables in files” feature inside a “Deploy package step”.

Again I understand.

A couple of additional options:

You could add a pre-deploy script to your package-step (either as a script included in the package, or a script configured on the step), which sets an output variable to your desired value. For example, your PreDeploy.ps1 could contain:

Set-OctopusVariable -name "HostName" -value ([System.Net.Dns]::GetHostName())

Becuase pre-deploy scripts run before variable-substitutions, this variable could then be used in your variable substitution expressions: #{HostName}

As a simpler option, environment variables are automatically available as Octopus variables. So if the physical machine name is suitable for your purpose, you could always use #{env:COMPUTERNAME} in your file to be substituted.

Do either of these options help?

Great!, that worked perfectly.

Thank you very much Michael

You’re most welcome. I’m very glad to hear it’s working.

Happy Deployments!
Michael