LepardUK
LepardUK

Reputation: 1360

Octopus Script to set Variable for use in ARM template Deployment

I have simple requirement that I can achieve in Azure DevOps and other release management systems but seems to be actively prevented in Octopus Deploy.

I want to run an ARM Template deployment step using Parameter substitution. This is supported out of the box for variables saved into the project before creation, but I want to determine the value of a variable as a result of a script and then use that variable as one of the substitutions.

In ADO I can do the following to save a variable value into the scope of the release

Write-Host "##vso[task.setvariable variable=Colour]Green"

In Octopus I have SetVariable - but bizarrely it has the scope of the current step only, which is not much use.

I can use

 [Environment]::SetEnvironmentVariable("colour","green","machine")

But this will not be read by the ARMS substitution mechanism

How can I set a variable to use in a subsequent step?

Upvotes: 1

Views: 1018

Answers (1)

ryan.rousseau
ryan.rousseau

Reputation: 1655

You can do this with Output Variables in Octopus Deploy.

An output variable set in one step will be available in the following steps.

In a step named "StepA":

Set-OctopusVariable -name "TestResult" -value "Passed"

In a following step:

$TestResult  = $OctopusParameters["Octopus.Action[StepA].Output.TestResult"]

I usually recommend wrapping that output variable syntax in a project variable to make it easier to manage.

For the above example, I would create a project variable named something like Project.TestResult and give it a value of #{Octopus.Action[StepA].Output.TestResult}

That way, you can reference the output variable with the simpler variable name. This isn't required but can help simplify things.

Upvotes: 1

Related Questions