Select variables based on others

Is there anyway to select or scope variables for a deployment based on another? For example lets say I have a variable called location, based on what is entered for this variable for each tenant, I would then like to automatically use the URL for downloading installers in the same location. The location name does not feature in the URL so I can’t just use variable substitution.

Hi Sam,

Thanks for the question.

As an alternative to selected a variable based on another variable, you could create a Tenant Tag Set for your location and add a Tag for each location. You could then create a variable with a value scoped to each Tag.

For the location example, create a tag set called “Location” and add the tags “London”, “New York”. Create a variable in your project or in a library variable set called “InstallerUrl” and add the value “http://london.download.com/installer.exe” scoped to London and “http://newyork.download.com/installer.exe” scoped to New York.

I hope this helps.

Cheers,
Shane

I did think about that, however we have instances where a single tenant may have environments in different locations.

Hi Sam,

In recent versions of Octopus you can used indexed variables. For example:

  • Define a variable template called “location”
  • Set the value of location in each of your tenants for project-environments
  • Define a variable on the project called “downloadUrl[London]” with value “http://london.download.com/installer.exe” and “downloadUrl[NewYork]” with value “http://newyork.download.com/installer.exe
  • Define a project variable called “resolvedDownloadUrl” and set the value to “#{downloadUrl[#{location}]}”

Now when a tenant location variable has the value “London”, “resolvedDownloadUrl” will have the value “http://london.download.com/installer.exe”.

Cheers,
Shane