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 1.12.0.0 I want 1.12.sql to be executed and if I’m deploying 1.13.45.5 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.

Hi,

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 3.2.1.0

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

Hope that helps,
Dalmiro

Thanks a lot Dalmiro. It helped.