Get Version Number For Tenant and Environment when executing a Runbook

I have a runbook, that I run on a specific environment and tenant. In that Runbook, I need to use the version number that is deployed to that environment and tenant.

I tried using the following:

  • Octopus.Release.PreviousForEnvironment.Number
  • Octopus.Release.CurrentForEnvironment.Number

But they are empty when using a Runbook (I assume because a Runbook does not use a release).

Is there a way to get the version number that the Runbook is running, given its context of knowing Octopus.Deployment.Tenant.Id, Octopus.Environment.Id and Octopus.Project.Id (and the associated name variables)?


Thanks for reaching out!

You are correct, Runbooks behave a little differently as they don’t have ‘Releases’ but rather ‘Snapshots’ and so the variables are slightly different.

I believe the variable you are looking for is either “Octopus.RunbookSnapshot.Id” or “Octopus.RunbookRun.Id” but you can check out all the different system variables for Runbooks here.

Feel free to let me know if you have any further questions or if that isn’t what you are after!

Best Regards,

Not quite what I am looking for.

When you run a Runbook you pick an environment (and a tenant if configured to do so). I need to know the version of the release that is deployed to that environment (and tenant).

Hi OctopusSchaff,

I’m just jumping in for Finnian as he’s finished for today. I am not quite sure I understand what your after, but I will try to clarify a little bit and provide hopefully a good starting point.

“Release” is generally a term associated with the project, not Runbooks. Any modification, (including creating snapshots or running Published or Draft runbooks) will not have any effects on the Project where the Runbook is accessed from.

There are a number of variables that are unique to a runbook. I’ve Bolded the variable below and provided an example output.

Runbook ID Runbooks-362
Runbook Name Runbook Details
Octopus.Runbook.Id Runbooks-362
Octopus.RunbookRun.Id RunbookRuns-1079
Octopus.RunbookRun.Name Run on Development example for Tenants
Octopus.RunbookSnapshot.Id RunbookSnapshots-714
Octopus.RunbookSnapshot.Name Snapshot Q26BDDP
Octopus.RunbookSnapshot.Notes Manually entered Notes
Octopus.Web.RunbookSnapshotLink /app#/Spaces-162/snapshots/RunbookSnapshots-714
Octopus.Web.RunbookRunLink /app#/Spaces-162/runs/RunbookRuns-1079

Here’s an example of how you would access it in a runbook. $OctopusParameters[“Octopus.Runbook.Id”]

You can also use API calls to interrogate your runbooks.

Here is an example script, that will take a Tenant Name, Environment Name and Project Name and return any runbook runs that meet that specific criteria.

$ErrorActionPreference = "Stop";

# Define working variables
$octopusURL = ""
$header = @{ "X-Octopus-ApiKey" = $octopusAPIKey }
$spaceName = "Default"
$projectName = "Project Name with Runbooks"
$tenantName = "Client A"
$environmentName = "Development"

# Get Space from Space Name
$space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName}

# Get the ID of the Project, Tenant and Environment based on the name.
$project = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects/all" -Headers $header) | Where-Object {$_.Name -eq $projectName}
$environment = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/Environments/all" -Headers $header) | Where-Object {$_.Name -eq $environmentName}
$tenant = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/tenants/all" -Headers $header) | Where-Object {$_.Name -eq $tenantName}

# Get Entire List of Runbookruns from Space.Id
$runbookruns = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/runbookRuns" -Headers $header) 

# Return Results based on Tenant, Project and Environment
$results = $runbookruns.Items | Where-Object {($_.TenantId -eq $tenant.Id) -and ($_.ProjectId -eq $project.Id) -and ($_.EnvironmentId -eq $environmentId)}


I am hoping that this will be enough information for you to put together what you need to, in order to get exactly the information you are after. If I have missed the end goal of what you were trying to achieve, Myself or Finnian (or any other member of the support team) will be more than happy to keep helping you out.

Please, just reach out, and try to clarify exactly the output you are after. Perhaps an Mock example of what you wish the output to look like.



I apologize for not giving a clear description of what I am trying to accomplish.

I have a Runbook that will run a Helm chart. The same Helm chart is also run as part of a Release’s “Process”. It is a Custom Step Template that us used both in the Release and in the Runbook.

The Helm Chart sets up Istio to point a routing to the newly deployed release. But I would like my operations team to be able to set this routing manually. (Hence, I need to run it from both the Release and the Runbook.)

When the Release runs the Helm Chart step, it uses the release’s version number as the version number passed to helm for the Chart’s version number.

When I run the Runbook, I am asked for an Environment and a Tenant:

With that I would like to get the version number that is currently in the project for that Environment and Tenant (in my picture that is, for the Dev environment and the Blue tenant).

That way I can set the helm chart version number to be + the numeric part of the Runbook’s run Id. (ie

I was hoping that I would not need to make Rest calls to pull that off, but it is sounding like I may have to do that. :frowning:

(Rest calls are hard because I copy my projects from a central template. That means I have to set a variable in the central template that has credentials to see all the projects (giving all projects that access), or I have to make credentials for each project separately.)

OK, so I thought Helm was going to be picky about the version number going up and down.

I was able to run a test where I just default the version number to 1.0.0 for the Runbook and it works fine. While it would be nice to to have the version number as I described above, it is absolutely not worth the effort it will take.

Sorry for the poor question. I will ensure my questions are structured better in the future.


Glad you were able to get a working resolution, sorry there wasn’t an easy way to achieve what you were after!

We always appreciate your questions, they are generally well structured and you’re always responsive and patient with us! Thank you :slight_smile:

Best Regards,

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.