如何从 PowerShell 在 Octopus Deploy 中设置系统变量值

How to set system variable value in Octopus Deploy from PowerShell

我试图在 "Run a Script" 步骤中为内置发行说明变量赋值。

$OctopusParameters["Octopus.Release.Notes"] = "Some release notes"

下一步"Send an Email"我在电子邮件正文中使用这个变量,但不幸的是它是空的。

<p>#{Octopus.Release.Notes}</p>

是否可以从 PowerShell 设置 Octopus Deploy 系统变量值并在下一步中使用它?

我正在使用 Octopus Deploy 3.7.11。

编辑:

我也尝试了 cmdlet Set-OctopusVariable 但它没有用。

Set-OctopusVariable -name "Octopus.Release.Notes" -value "Something"

我用 Octoposh 试过了。在 Modifying Variables - Edit a variable of a Project/Library variable set.

的 Octoposh wiki 中介绍了修改现有变量的内容

由于我们的网络超时,我无法让它工作,但它看起来应该可以工作 - 只是不像我预期的那样 straight-forward。

我认为不可能覆盖 Octopus Deploy 提供的 built-in 变量的值。但是您可以定义自己的输出变量并在以下步骤中引用它。例如,在您的 'Run a script' 步中使用:

Set-OctopusVariable -name "MyReleaseNote" -value "Some text here"

然后 "Send an Email"-step 可以使用以下内容引用此文本(假设第一步称为 'FirstStep'):

#{Octopus.Action[FirstStep].Output.MyReleaseNote}

该变量也可以在其他步骤中从脚本中使用,然后使用语法:

$relnote = $OctopusParameters["Octopus.Action[FirstStep].Output.MyReleaseNote"]

(如果你想保存生成的releasenote,也许你可以将它保存为项目中的'artifact')。