在 Octopus Deploy 中,第一次将主要或次要版本部署到环境时如何要求批准?

Posted

技术标签:

【中文标题】在 Octopus Deploy 中,第一次将主要或次要版本部署到环境时如何要求批准?【英文标题】:In Octopus Deploy, how to require an approval when a major or minor version is deployed to an environment the first time? 【发布时间】:2020-02-18 16:01:14 【问题描述】:

假设您有五个环境,开发、测试、UAT、阶段和生产。

对于这些环境,您具有以下生命周期: - 冲刺:开发 -> 测试 - 测试到产品:测试 -> UAT -> 阶段 -> 产品 - UAT 到 Prod:UAT -> Stage -> Prod - Hotfix: Stage -> Prod

发布版本类似于 2020.1.3。当新版本被删减时,它将更新版本号中的主要 (2020) 或次要 (1)。例如 2020.1.3 转到 2020.2.1 或 2021.1.1。错误修复或次要版本将更新最后一个数字 (3)。

问题在于,如果在错误的时间或意外将发布部署到测试、UAT 或阶段,它会阻止我们的测试人员。例如,QA 正在测试中测试 2020.1.3 版本。一位开发人员不小心将 2020.2 推到了测试阶段。这包括 QA 没有预料到的新代码。虽然 QA 正在测试 2020.1.x,但他们只想查看 2020.1.x 版本。

我们不想在我们的频道中使用version rules。每次削减新版本时,都必须更新版本规则。

第一次将主要或次要版本部署到环境时是否可能需要批准?

【问题讨论】:

【参考方案1】:

是的,这是可能的。为此,我们将使用output variables 和run conditions。

首先,在流程开始时添加了两个新步骤。

这两个步骤都跳过了开发和生产,因为它们不受此问题的影响。每次主要/次要版本更改时都必须批准部署到 dev 将很快变老。并且所有生产版本至少必须先进入暂存阶段。

第一步运行这个 PowerShell 脚本。它将将此特定环境的先前版本号与当前版本号进行比较。如果主要或次要版本不同,它会将输出变量“RequiresApproval”设置为 true。

$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

输出变量有点冗长,使用起来可能很棘手。为了使这更容易,请创建一个项目变量来引用它。

在手动干预步骤中,将运行条件设置为该项目变量。

现在是时候测试一下了。 UAT 目前拥有2020.1.2,而测试拥有2020.2.3。当2020.2.4 部署到测试时,不应出现手动干预。

成功,跳过人工干预。

UAT 目前有2020.1.22020.2.4 有一个新的次要版本,部署到 UAT 会提示用户手动干预。

This YouTube Video 展示了这一点。

【讨论】:

以上是关于在 Octopus Deploy 中,第一次将主要或次要版本部署到环境时如何要求批准?的主要内容,如果未能解决你的问题,请参考以下文章

在 Octopus Deploy 中为多个项目定义角色和环境

在 Octopus Deploy 中,您可以使用每个环境设置的变量作为 feed 的值吗?

Octopus Deploy:如何将不同的项目部署到不同的生产机器上

GitVersion:Octopus Deploy 在 Nuget 包版本上拒绝了多个候选版本

powershell 自动执行Octopus Deploy Server安装和配置

部署应用程序时,Octopus Deploy 未合并我的转换文件