Custom install directory based on package version

Hi folks,

We have a strange scenario we’re trying to deal with where the custom install directory for a particular project depends on the “major.minor” part of the release number (or, strictly speaking, the Nuget package version, as it’s a single-package project).

So, for example, package version 1.3.0.7 should deploy to \AppName\1.3
Version 2.1 should deploy to \AppName\2.1
etc.

Is there any easier way to set this up other than creating a Powershell step to extract the major.minor and then passing this through to the deployment step? (or, of course, just deploying to 1.3.0.7 and renaming the folder post-deployment :slight_smile: )

Thanks!

Hi,

Thanks for reaching out! I’m afraid there’s no easy way to do this that doesn’t require come Powershell magic. I would personally go with the folder renaming strategy using a script on the same Package Deploy Step, simply to avoid extra steps on the process.

Thanks,
Dalmiro

Thanks Dalmiro!

We might just take an easier option and prompt them for that value in a variable. :slight_smile:

Hi there!

As someone that automates processes for a living, i cannot stress enough how much I recommend you to avoid having users manually typing values :slight_smile:

I gave this a thought and I think you could do something like this:

1 - Disable the Custom Installation Directory feature

2 - Enable Scripts in package steps

3 - As a PRE deploy script, use the below script which should create your folder provided a base path for it. If you provide c:\deploy as base path and your package version is 5.1.2, It’ll create the folder c:\deploy\5.1

##CONFIG##
$RootPath = "C:\deploy\" #Base path where the folder with the 2 digits of the package version will be on. If you set this to C:\Deploy, your final path should be c:\deploy\1.0\ . Totally recommended to use a variable here so you can re-use it for the post-deploy script.

##PROCESS##
[version]$version = $OctopusParameters['Octopus.Action.Package.NuGetPackageVersion']

[string]$ShortVersion = [string]$version.Major + "." + [string]$version.Minor

$Path = Join-Path $RootPath $ShortVersion

New-Item $Path -ItemType Directory -Verbose -Force
  1. As a Post deploy script, use this (again, provided a base path) to copy the contents of the package to the newly created folder:
##CONFIG##
$RootPath = "C:\deploy\" #Base path where the folder with the 2 digits of the package version will be on. If you set this to C:\Deploy, your final path should be c:\deploy\1.0\ . Totally recommended to use a variable here so you can re-use it for the post-deploy script.

##PROCESS##
[version]$version = $OctopusParameters['Octopus.Action.Package.NuGetPackageVersion']

[string]$ShortVersion = [string]$version.Major + "." + [string]$version.Minor

$Path = Join-Path $RootPath $ShortVersion

copy-item -path .\* -destination $path -recurse -verbose

Gotchas:

  • Those scripts don’t take into account re-deployment scenarios. You’ll have to figure that one yourself :slight_smile:

  • That final destination folder will not be targeted by retention policies, so you’ll have to figure out a way to clean it up over time.

Hope that helps!
Dalmiro