Output Variables

Last updated

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 Walkthrough.

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

Deployment Process

Creating an Output Variable

Set-OctopusVariable -name "AppInstanceName" -value "MyAppInstance"
Octopus.SetVariable("AppInstanceName", "MyAppInstance");
set_octopusvariable "AppInstanceName" "MyAppInstance"
Octopus.setVariable "AppInstanceName" "MyAppInstance"
set_octopusvariable("AppInstanceName", "MyAppInstance")

Using the Variable in Another Step

$appInstanceName = $OctopusParameters["Octopus.Action[Determine App Instance Name].Output.AppInstanceName"]
var appInstanceName = Octopus.Parameters["Octopus.Action[Determine App Instance Name].Output.AppInstanceName"]
appInstanceName=$(get_octopusvariable "Octopus.Action[Determine App Instance Name].Output.AppInstanceName")
//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"
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>']