How can I require an approval when a major or minor version is deployed to an environment the first time?

deployment-config
logic-in-deployments
(Bob Walker) #1

We have five environments, Dev, Test, UAT, Stage and Production.

We have different lifecycles:

  • Sprint: Dev -> Test
  • Test To Prod: Test -> UAT -> Stage -> Prod
  • UAT to Prod: UAT -> Stage -> Prod
  • Hotfix: Stage -> Prod

When we cut a new release we will either update the major (2020) or minor (1) in our version number, 2020.1.3. When we create a new bug fix release we only update the last number (3).

Our concern is if a release is deployed to Test, UAT or Stage at the wrong time or by accident and it stops our testers. For example, QA is in the middle of testing the 2020.1.3 release in Test. A developer accidentally pushes 2020.2 up to Test. That includes new code QA wasn’t expecting. While QA is in the middle of testing 2020.1.x they only want to see 2020.1.x releases. Due to how our lifecycles overlap channel version rules won’t work.

(Bob Walker) unlisted #2
(Bob Walker) #3

This solution will use output variables and run conditions.

What I did was add two new steps to the start of the process:

Both steps skip development and production because they are not affected by this problem. Having to approve a deployment to dev every time a major/minor version changes will get old really fast. And all production releases must at least go to staging first.

The first step runs this PowerShell script. It will compare the previous release number for this specific environment with the current release number. It will set the output variable “RequiresApproval” to true if either the major or minor version is different.

$releaseNumber = $OctopusParameters["Octopus.Release.Number"]
$releaseNumberArray = $releaseNumber.Split('.')

$lastVersion = $OctopusParameters["Octopus.Release.PreviousForEnvironment.Number"]
$lastVersionArray = $lastVersion.Split('.')

Write-Highlight "The previous version deployed to this environment was $lastVersion"

$requiresApproval = $false
if ($lastVersionArray[0] -ne $releaseNumberArray[0])
{
    Write-Highlight "The previous major version $($lastVersionArray[0]) in $lastVersion is different than the one being deployed $($releaseNumberArray[0]) in $releaseNumber, this requires someone to approve"
    $requiresApproval = $true
}
elseif ($lastVersionArray[1] -ne $releaseNumberArray[1])
{
    Write-Highlight "The previous minor version $($lastVersionArray[1]) in $lastVersion is different than the one being deployed $($releaseNumberArray[1]) in $releaseNumber, this requires someone to approve"
    $requiresApproval = $true
}
else
{
	Write-Highlight "The previous version's major and minor versions are the same, skipping approval"
}

Set-OctopusVariable -name "RequiresApproval" -value $requiresApproval

To make referencing the output variable easier I created a project variable to reference it:

In the manual intervention step I set the run condition to that project variable.

UAT currently has 2020.1.2 while Test has 2020.2.3. When I deploy 2020.2.4 to QA I shouldn’t see a warning.

Which I don’t:

But when it is deployed to UAT I am prompted to approval the release:

To see this in action, you can view the video here: https://www.youtube.com/watch?v=1ETQYga_wxQ

(Bob Walker) listed #4