Release major, minor, patch version number in variables

I have a Powershell script task in that I want to use the version number.
I have a website that I want to deploy, and I want to deploy it in subfolders named after the major, minor and patch
For example, HTTP://myapp/v1/02/ and its physical path will be c:\webs\myapp\v1\02\b220619
where the version is 1.2.0-b220619
Right now, I have the major, minor, and build numbers as variables but it would be really nice if I could read it from the Release I create in Octopus Deploy

You could reference the #{Octopus.Release.Number} system variable in your step.

Hi @cherrington,

Thanks for the question! I just wanted to jump in to supplement on to what John mentioned regarding the #{Octopus.Release.Number} system variable. You can expand on that by using some extraction filters, link to the relevant section in the docs below.

For example, using your release version (1.2.0-b220619), #{Octopus.Release.Number | VersionMajor} would return 1, and similarly VersionMinor, VersionPatch, and VersionPreRelease would return different sections of the version string accordingly, which you could use to build the path desired.

I hope this helps! Let us know if you have any further questions or concerns going forward!

Best regards,

Kenny

Could variable filters also be used on the package version?
It occurred to me that it’s a specific version of the package that I am trying to deploy, so ideally, id like to name the release after the package version, but I am also trying to use the extraction filters in the Powershell script I am running, and it doesn’t seem to be working.
For example, I am trying to do:

Import-Module WebAdministration
$major = "v" + $OctopusParameters["Octopus.Action.Package[MyPackage].PackageVersion | VersionMajor"]


Write-Output "Creating $appName\$major" 
If((Test-Path IIS:\Sites\$appName"\"$major) -eq 0) {
    New-Item -ItemType directory -Path $websFolder$appName"\"$major
    New-WebVirtualDirectory -Site $appName -Name $major -PhysicalPath $websFolder$appName"\"$major
    ConvertTo-WebApplication -PSPath IIS:\Sites\$appName"\"$major -ApplicationPool $appName
}

But when I look at the folder it is creating, its only named v

Hi @cherrington,

Thanks for your follow-up question!

If you want to associate release versions based on a package in a deployment, you can configure this under your project’s Deployments > Settings > Release Versioning section. In there, you should see an option to use the version number from an included package, and this option will allow you to pick your step with the desired package. I thought this feature might be helpful given your use case.

We also have a few more notes regarding custom release versioning at the following link in case you haven’t seen it yet:

Regarding your scripting, I’ve tested the following syntax to work in a ‘Run a Script’ step, or as a post-deployment script in a ‘Deploy a Package’ step:

$major = "v" + #{Octopus.Action[Deploy a Package].Package.PackageVersion | VersionMajor}

Write-Host $major

Note that the syntax may change a bit depending on what type of step you’re using, but in the case of a ‘Deploy a Package’ step under that same name, I only needed to specify the name of the step, .Action[Deploy a Package].

I hope that’s helpful, but let us know if you have further questions or issues.

Best regards,

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