Octopus allows you to define variables and scope them for use in different environments when running a Runbook. Variables allow you to have a consistent Runbook process across your infrastructure without having to hard-code or manually update configuration settings that differ across environments, deployment targets, channels, or tenants. In addition to environments, you can scope variables to specific Runbooks.
- From the Hello world project you created earlier, click Variables in the left menu.
- Enter Helloworld.Greeting into the variable name column on the first row of the table.
- Add Hello, Development Runbook into the value column.
- Click the Scope column and select the
Development
environment and Hello runbook process. - Click ADD ANOTHER VALUE button.
- Add Hello, Test Runbook and scope it to the
Test
environment and Hello runbook process. - Click ADD ANOTHER VALUE button.
- Add Hello, Production Runbook and scope it to the
Production
environment and Hello runbook process. - Click the SAVE button.
During a runbook run or deployment, Octopus will select the most specifically scoped variable that applies. In the screenshot above, when running Hello Runbook in Production, Octopus will select Hello, Production Runbook
. When running a different runbook or doing a deployment to Production, Octopus will select Hello, Production
.
Steps in the runbook process can reference the variables.
- Click Runbooks on the left menu.
- Click Hello Runbook in the list of runbooks.
- Click Process in the runbook menu.
- Select the script step.
- Change the script in the script step based on your language of choice:
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 the SAVE button.
- Click the RUN… button, select and environment, and run the Runbook.
The next step will add deployment targets to run runbooks on.
Further Reading
For further reading on Runbook variables please see:
Help us continuously improve
Please let us know if you have any feedback about this page.
Page updated on Tuesday, July 30, 2024