Octopus allows you to define variables to customize your deployments. These variables, along with some predefined variables, will automatically be made available to your scripts as global variables.
All variables are strings Note that in scripts all Octopus variables are strings even if they look like numbers or other data types. You will need to cast to the appropriate type before using the value if you need something other than a string.
Let’s consider an example where we have defined a project variable called MyApp.
PowerShell
# It's a good idea to copy the value into a local variable to avoid quoting issues
$connectionString = $OctopusParameters["MyApp.ConnectionString"]
Write-Host "Connection string is: $connectionString"C#
// It's a good idea to copy the value into a local variable to avoid quoting issues
var connectionString = OctopusParameters["MyApp.ConnectionString"];
Console.WriteLine("MyApp.ConnectionString: " + connectionString);Bash
# It's a good idea to copy the value into a variable to avoid quoting issues
connectionString=$(get_octopusvariable "MyApp.ConnectionString")
echo "Connection string is: $connectionString"Python3
connectionString = get_octopusvariable("MyApp.ConnectionString")
print(connectionString)Variables in PowerShell scripts
In PowerShell we have pre-defined some script-scoped variables for you as a convenience. Consider the same example as before, a variable named “MyApp.ConnectionString” will be available as both:
$OctopusParameters["MyApp .ConnectionString"] $MyAppConnectionString
In the first form the variable name appears just as they appear in the Octopus Web Portal, while in the second example special characters have been removed. The first form is the most flexible, but in some cases the second form may be more convenient.