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

Vik*_*lle 4 octopus-deploy

我试图在“运行脚本”步骤中为内置发行说明变量赋值。

$OctopusParameters["Octopus.Release.Notes"] = "Some release notes"
Run Code Online (Sandbox Code Playgroud)

在下一步“发送电子邮件”中,我在电子邮件正文中使用此变量,但不幸的是它是空的。

<p>#{Octopus.Release.Notes}</p>
Run Code Online (Sandbox Code Playgroud)

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

我使用的是 Octopus Deploy 3.7.11。

编辑:

我也尝试过 cmdlet Set-OctopusVariable,但没有成功。

Set-OctopusVariable -name "Octopus.Release.Notes" -value "Something"
Run Code Online (Sandbox Code Playgroud)

小智 5

我认为不可能覆盖 Octopus Deploy 提供的内置变量的值。但是您可以定义自己的输出变量并在以下步骤中引用该变量。例如,在“运行脚本”步骤中使用:

Set-OctopusVariable -name "MyReleaseNote" -value "Some text here"
Run Code Online (Sandbox Code Playgroud)

然后“发送电子邮件”步骤可以使用以下内容引用此文本(假设第一步称为“FirstStep”):

#{Octopus.Action[FirstStep].Output.MyReleaseNote}
Run Code Online (Sandbox Code Playgroud)

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

$relnote = $OctopusParameters["Octopus.Action[FirstStep].Output.MyReleaseNote"]
Run Code Online (Sandbox Code Playgroud)

(如果您想保存生成的发行说明,也许您可​​以将其保存为项目中的“工件”)。