Variable Substitutions in Octopus 1.2.2

Published on: 1 Dec 2012

Octopus 1.2.2 includes support for variable substitutions, which allows parts of a variable to reference another variable.

For example, prior to Octopus 1.2.2, I had this variable defined:

Old variables

After upgrading to 1.2.2 I can now use a single variable that references one of the pre-defined variables.

New variables


Variables can reference other variables, which can reference other variables, and so on. During deployment, the Octopus Server will select the variables that are "in-scope" (based on the environment being deployed to, etc.) and push them to the Tentacle. The Tentacle will then set some additional special variables (such as OctopusOriginalPackageDirectoryPath), and then it will resolve the value of all variables by applying any substitutions. During this process, it will check for cyclic dependencies and throw an exception if a cycle is detected.

Customizing how substitutions work

If a variable references another variable that isn't defined, the default behavior is to throw. You can customize this by setting the special variable OctopusIgnoreMissingVariableTokens to true to simply ignore the expression.

If you want to opt out of this feature entirely, set OctopusNoVariableTokenReplacement to true.

By default, Octopus expects variables to be in the form of #{Name}. If that syntax doesn't work for you, you can customize it by setting a custom regex in the variable OctopusVariableTokenRegex. The default regex used is \#\{(?<variable>.+?)\}.

If you need to check whether your variables are being substituted correctly, set the two special variables PrintVariables and PrintEvaluatedVariables to true to print the values before/after resolving.

Hopefully this feature will make defining variables much easier.

Octopus Deploy is used by thousands of developers across the globe, from small companies to large enterprises. Find out if it meets your deployment automation needs by taking advantage of our free 30-day trial. You can spin up an instance with just a few clicks!