How to set system variable value in Octopus Deploy from PowerShell

不羁的心 提交于 2019-12-13 15:06:21

问题


I am trying to assign value to built-in release notes variable in "Run a Script" step.

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

In the next step "Send an Email" I am using this variable in email body, but unfortunately it is empty.

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

Is it possible to set Octopus Deploy system variable value from PowerShell and use it in the next step?

I am using Octopus Deploy 3.7.11.

EDIT:

I have also tried the cmdlet Set-OctopusVariable and it did not work.

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

回答1:


I don't think it is possible to overwrite values of the built-in variables provided by Octopus Deploy. But you could define your own output variable and refer to that in the following steps. For example in your 'Run a script'-step use:

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

Then the "Send an Email"-step can refer to this text by using the following (assuming the first step is called 'FirstStep'):

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

The variable can also be used from a script in other steps, then use the syntax:

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

(If you want to save the generated releasenote perhaps you could save it as an 'artifact' in the project).




回答2:


I tried this using Octoposh. Modifying an existing variable is covered in the Octoposh wiki at Modifying Variables - Edit a variable of a Project/Library variable set.

I wasn't able to get this to work because of timeouts on our network, but it looks like it should work - just not as straight-forward as I expected.



来源:https://stackoverflow.com/questions/41607706/how-to-set-system-variable-value-in-octopus-deploy-from-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!