Octopus.Release.CurrentForEnvironment.Number for initial deployments

What is the value of the system variable “Octopus.Release.CurrentForEnvironment.Number” for the initial deployment in an environment? I was expecting to return an empty value, but in my script the variable is not being expanded.

One more question: does this system variable take into account a tenant? I mean, if I have two tenants with different versions for the same environment, the system variable “Octopus.Release.CurrentForEnvironment.Number” returns different values depending where it is being installed?

Thanks in advance

Bruno

Hi Bruno,

Thanks for getting in touch! I would expect it to return an empty value as well. When testing this locally, the script write-host #{Octopus.Release.CurrentForEnvironment.Number} returns an empty value. It then returns the correct value (i.e. 0.0.1) on subsequent deployments.

However, when I run:

$ReleaseNumber = "#{Octopus.Release.CurrentForEnvironment.Number}"
Write-host $ReleaseNumber

It returns #{Octopus.Release.CurrentForEnvironment.Number} on the first deployment. How are you using this variable, and what do you mean specifically by not being expanded?

Regarding tenants, this variable will return the value of the last successful deployment to the current environment for that tenant. For instance, if Tenant2 has release 2.0.0 deployed to it to Dev, but Tenant1 has 1.0.0 deployed to Dev, a deployment of release 1.0.1 to Tenant1 will return 1.0.0.

I hope this helps! Let me know how you go or if you have any further questions going forward. :slight_smile:

Kind regards,

Kenny

“By not being expanded”, I mean exactly what you have for 2nd case, i.e,
#{Octopus.Release.CurrentForEnvironment.Number}

Originally I was using this variable as part of the target destination of the “Compress Folder” task. Something like this

#{Target.DeployBackupsBasePath}#{Octopus.Release.CurrentForEnvironment.Number}.zip

Then I started using inside a PS script, and in order to work I needed to do something like this

If ($OctopusParameters[“Octopus.Release.CurrentForEnvironment.Number”] -eq $null) {
$CurrentVersion = “0.0.0”
} Else {
$CurrentVersion = $OctopusParameters[“Octopus.Release.CurrentForEnvironment.Number”]
}

Btw, from your answer I can see that you are using the syntax #{varName} inside poweshell. Is this possible? I thought that inside powershell I would need to use the $OctopusParameters powershell variable.

Hi Bruno,

Thanks for following up! The syntax #{Var} is the variable substitution syntax, where Octopus will only simply replace it as a matching variable name’s value. You can perform variable substitution in your PowerShell scripts. Though it’s great to hear you’ve reached the solution to get this working! Don’t hesitate to reach out if you have any further questions going forward. :slight_smile:

Kind regards,

Kenny

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