Documentation and Support Documentation and Support

Output variables

Your scripts can emit variables that are available in subsequent deployment steps. This means you can factor your deployment into smaller, more well-defined steps that leverage the result of prior steps. It is an extremely powerful feature and you should refer to the documentation on output variables for more information.

This example is from the sample project in the Channels Walk-through.

Step 1 calculates a name by convention, which is used by subsequent steps.

Deployment Process

Creating an output variable

PowerShell
Set-OctopusVariable -name "AppInstanceName" -value "MyAppInstance"
C#
Octopus.SetVariable("AppInstanceName", "MyAppInstance");
Bash
set_octopusvariable "AppInstanceName" "MyAppInstance"
F#
Octopus.setVariable "AppInstanceName" "MyAppInstance"
Python3
set_octopusvariable("AppInstanceName", "MyAppInstance")

Using the variable in another step

PowerShell
$appInstanceName = $OctopusParameters["Octopus.Action[Determine App Instance Name].Output.AppInstanceName"]
C#
var appInstanceName = Octopus.Parameters["Octopus.Action[Determine App Instance Name].Output.AppInstanceName"]
Bash
appInstanceName=$(get_octopusvariable "Octopus.Action[Determine App Instance Name].Output.AppInstanceName")
F#
//throw if not found
let appInstanceName1 = Octopus.findVariable "Octopus.Action[Determine App Instance Name].Output.AppInstanceName"

//supply a default value to use if not found
let appInstanceName2 = Octopus.findVariableOrDefault "Value if not found" "Octopus.Action[Determine App Instance Name].Output.AppInstanceName"

//return an Option type
let appInstanceName3 = Octopus.tryFindVariable "Octopus.Action[Determine App Instance Name].Output.AppInstanceName"
Python3
appInstanceName = get_octopusvariable("Octopus.Action[Determine App Instance Name].Output.AppInstanceName")

Service message

The following service message can be written directly (substituting the properties with the relevant values) to standard output which will be parsed by the server and the values processed as an output variable. Note that the properties must be supplied as a base64 encoded UTF-8 string.

##octopus[setVariable name='<Base64Encoded-VariableName>' value='<Base64Encoded-VariableValue>']

Help us continuously improve

Please let us know if you have any feedback about this page.

Send feedback

Page updated on Sunday, January 1, 2023