Octopus lets you define variables and scope them for use in different phases of your deployments. Variables allow you to have a consistent deployment process across your infrastructure without having to hard-code or manually update configuration settings that differ across environments, deployment targets, channels, or tenants.
Add a variable
- From the Hello world project you created earlier, click Project Variables in the left menu.
- Click Create Variables.
- Add
Helloworld.Greeting
in the Name column, - Add
Hello, Development
in the Value column, - Click the Scope column and select the
Development
environment. - Click Add another value.
- Add
Hello, Staging
and scope it to theStaging
environment. - Click Add another value.
- Add
Hello, Production
and scope it to theProduction
environment. - Click Save.
Update deployment process
Steps in the deployment process can reference variables.
- Click Process in the left menu.
- Select the previously created Run a Script step.
Inline Source Code
- Based on your selected language, copy the appropriate script from below.
- Replace the script in the code editor with the new script.
PowerShell
Write-Host $OctopusParameters["Helloworld.Greeting"]
Bash
greeting=$(get_octopusvariable "Helloworld.Greeting")
echo $greeting
If you are using Octopus Cloud, Bash scripts require you to select the Hosted Ubuntu worker pool. The Default Worker Pool is running Windows and doesn’t have Bash installed.
- Click Save
- Click Create Release.
A release snapshots everything about your project, including variables and the deployment process. You have to create a new release to see any changes.
As you promote through the environments, you will see the greeting change.
Great job! Next, let’s build on your deployment process and add an approval process using manual interventions.
All guides in this tutorial series
- First deployment
- Define and use variables (this page)
- Approvals with manual interventions
- Add deployment targets
- Deploy a sample package
Further reading for variables
Help us continuously improve
Please let us know if you have any feedback about this page.
Page updated on Wednesday, November 13, 2024