Passing release variables between two agent phases

谁说我不能喝 提交于 2019-11-29 10:20:26

There is no way to persist variables (no matter powershell variables or VSTS user defined variables) between two agent phases (and environments) for now.

And there is a related issue Variables set via logging commands are not persistent between agents, you can follow up.

The work around for now is define the variable again in next agent phase.

You can share a variable between the agent phases by using the TFS Rest API and creating a new variable in the release.

You can create a helper module to facilitate this task.

  1. Get the release by using the environment variable $Env:Release_ReleaseId.
  2. Add a NoteProperty, using Add-Member, to the variables hashtable of the release returned in step 1, where the name is your desired variable name and the value is a ConfigurationVariableValue.
  3. Save the release with the added variable.

In order to use this approach, you would set the variable in your first agent. Then, in the second agent, you can simply read the TFS variable using the $(VariableName) semantic.

I've used the "Variable dehydration task" to write the value to my artifact folder in a build pipeline. I then read the json with inline-powershell. Currently, I'm reading it on every task in my release pipeline, which seems mental to me, but it sort of works. You ought to be able to set a global or env? variable and use that instead. Supposedly fixed in 2017, but I'm using 2015.

The right way to do it is using Variablegroups to persist between pipelines: https://docs.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups?view=azure-devops&tabs=yaml

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