Runbook specific variables

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.

  1. From the Hello world project you created earlier, click Variables in the left menu.
  2. Enter Helloworld.Greeting into the variable name column on the first row of the table.
  3. Add Hello, Development Runbook into the value column.
  4. Click the Scope column and select the Development environment and Hello runbook process.
  5. Click ADD ANOTHER VALUE button.
  6. Add Hello, Test Runbook and scope it to the Test environment and Hello runbook process.
  7. Click ADD ANOTHER VALUE button.
  8. Add Hello, Production Runbook and scope it to the Production environment and Hello runbook process.
  9. Click the SAVE button.

The hello world variables

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.

  1. Click Runbooks on the left menu.
  2. Click Hello Runbook in the list of runbooks.
  3. Click Process in the runbook menu.
  4. Select the script step.
  5. Change the script in the script step based on your language of choice:
Write-Host $OctopusParameters["Helloworld.Greeting"]
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.

  1. Click the SAVE button.
  2. Click the RUN… button, select and environment, and run the Runbook.

The results of the hello world runbook run with variables

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.

Send feedback

Page updated on Sunday, January 1, 2023