Search code examples
octopus-deploy

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"

Solution

  • 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).