Replace #{Octopus.Version.LastMajor}.#{Octopus.Version.LastMinor} runtime

I want to present the values of #{Octopus.Version.LastMajor}.#{Octopus.Version.LastMinor} during run time of one of my script, but it isn’t happening. For example I have a powershell script which executes a SQL query from a folder containing 1.11.sql, 1.12.sql, 1.13.sql and these are branch wise sql files. If I’m deploying from I want 1.12.sql to be executed and if I’m deploying I want 1.13.sql to be executed. I’m trying hard to achieve and have already made scripts a mess. Need any simple solution where I can leverage existing Octopus functionalities.


Thanks for reaching out. You can do it using the system.version class along with the Octopus variable $OctopusParameters['Octopus.Release.Number'] like this:

[version]$ReleaseNumber = $OctopusParameters['Octopus.Release.Number']

#Lets say your release is

#$ReleaseNumber.major will hold "3"
#$ReleaseNumber.minor will hold "2"
#$ will hold "1"
#$ReleaseNumber.revision will hold "0"

Hope that helps,

Thanks a lot Dalmiro. It helped.