How to add an acquired value as a public variable to the deployment?

Currently you can add a variable during a deployment process, by setting it during a deployment step via PowerShell script; e.g.:
Set-OctopusVariable -name “VariableName” -value “Variable value”

To access this type of script-added variable within future deployment steps (via script), you must reference the actual step name that set it; e.g., if the deployment step that set the variable is named “Deploy Special Application”:
$acquiredVariable = $OctopusParameters[“Octopus.Action[Deploy Special Application].Output.VariableName”].

My question is: Is it possible to set an Octopus Variable via PowerShell script - that is globally/publicly available to all subsequent steps… so it can be accessed without requiring the name of the originating deployment step?

Hi Sean,

Thanks for reaching out. Output variables (this is the name of variables created by set-OctopusVariable) can only be retrieved referencing the step name.

If you are looking for something more “Global” I’d recommend you to put the values in JSON file on disk and consume them from there. Or use Environment variables as shown on the article below.

In the screenshot I’m showing:

  1. How to setup the variable
  2. setting the variable type to “Machine” so it persists between powershell sessions
  3. Getting the variable value
  4. Getting the variable value from another powershell console to prove it works on other PS sessions (which is what you need to make this work between steps)

I’d personally recommend the JSON approach as its easier to dispose of that file if you don’t want to leave tracks after the deployment.

Hope that helps,