Use powershell to populate an octopus variable for use in config substitution

Hello,

We use a powershell variable, let’s call it #{FQDN}, in the variable substitution step when deploying a package.
However, setting it via the UI is not ideal as we have quite a few machines.

Using #{Octopus.Machine.Hostname} does not work either as sometimes it’s the hostname without the domain (depending on how we installed it) and that makes the installation too fragile.

I can use powershell to easilly determine the FQDN but cannot figure out the best way to pass this to the substitution step…

Please can you advise how to achieve this, I’d rather not do the variable substitution with powershell but could if that was the only way…

Hi Andrew,

Thanks for reaching out! There’s a neat trick you can use here:

  1. Add a pre deploy script to your package step, and on it create a variable called FQDN using the below code:
$value = "Insert your custom magic to get the name you want"
set-octopusvariable -name FQDN -value $value
  1. In your config file, use the variable #{FQDN} wherever you want the value to be replaced.

Once you run the deployment, Octopus should replace the value of #{FQDN} with the variable set in the pre-deploy script set on (1).

Let me know if that helps,
Dalmiro