Vaccano
Vaccano

Reputation: 82291

Can Octopus Deploy have variables in variables

This is a system Octopus Deploy Variable:

#{Octopus.Action[Deploy To Server].Output.Package.InstallationDirectoryPath}

The text "Deploy to Server" is the name of the step in my project that deploys the Nuget Package to the server. This variable gives the install location of the NugetPackage.

I am wondering if I can make this more generic:

#{Octopus.Action[#{DeploymentStep}].Output.Package.InstallationDirectoryPath}

#{DeploymentStep} is itself a variable with the value of "Deploy to Server"?

I tried this and it not did do the substitution when it tried to run. But I am hoping there is a different syntax for variable in variable substitution.

(I want to do this so I can make this the default value for a Step Template.)

Upvotes: 3

Views: 3248

Answers (2)

IffiAnwar
IffiAnwar

Reputation: 1

Have just had the same issue, but with a few tests I got it working in a 1 liner. You need to encapsulate the inner variable in brackets with a dollar, and you need to change the double quotes within the variables to single quotes so it doesn't complain about the miss match of quotes. Double quotes on the outside and single quotes in the in.

The example below gets a step name with an octopus variable and also a the machine name it ran on variable to produce the result:

$OctopusParameters["Octopus.Action[$($OctopusParameters['Octopus.Step.Name'])].Output[$($OctopusParameters['Octopus.Machine.Name'])].MyVarFromMachineFromStep"]

Upvotes: 0

gvee
gvee

Reputation: 17161

It can be done; but you need to use slightly different syntax!

Variable substitution syntax: http://docs.octopusdeploy.com/display/OD/Variable+Substitution+Syntax

$deploymentStep = "#{DeploymentStep}"

$installationDirectory = $OctopusParameters["Octopus.Action[$deploymentStep].Output.Package.InstallationDirectoryPath"]

Upvotes: 4

Related Questions