Viktors Telle
Viktors Telle

Reputation: 783

How to set system variable value in Octopus Deploy from PowerShell

I am trying to assign value to built-in release notes variable in "Run a Script" step.

$OctopusParameters["Octopus.Release.Notes"] = "Some release notes"

In the next step "Send an Email" I am using this variable in email body, but unfortunately it is empty.

<p>#{Octopus.Release.Notes}</p>

Is it possible to set Octopus Deploy system variable value from PowerShell and use it in the next step?

I am using Octopus Deploy 3.7.11.

EDIT:

I have also tried the cmdlet Set-OctopusVariable and it did not work.

Set-OctopusVariable -name "Octopus.Release.Notes" -value "Something"

Upvotes: 4

Views: 7611

Answers (2)

Daniel Brixen
Daniel Brixen

Reputation: 1663

I don't think it is possible to overwrite values of the built-in variables provided by Octopus Deploy. But you could define your own output variable and refer to that in the following steps. For example in your 'Run a script'-step use:

Set-OctopusVariable -name "MyReleaseNote" -value "Some text here"

Then the "Send an Email"-step can refer to this text by using the following (assuming the first step is called 'FirstStep'):

#{Octopus.Action[FirstStep].Output.MyReleaseNote}

The variable can also be used from a script in other steps, then use the syntax:

$relnote = $OctopusParameters["Octopus.Action[FirstStep].Output.MyReleaseNote"]

(If you want to save the generated releasenote perhaps you could save it as an 'artifact' in the project).

Upvotes: 5

Tim Rourke
Tim Rourke

Reputation: 831

I tried this using Octoposh. Modifying an existing variable is covered in the Octoposh wiki at Modifying Variables - Edit a variable of a Project/Library variable set.

I wasn't able to get this to work because of timeouts on our network, but it looks like it should work - just not as straight-forward as I expected.

Upvotes: 0

Related Questions