VSTS : Can I access the Build variables from Release definition?

為{幸葍}努か 提交于 2019-12-06 09:22:10

问题


In VSTS CI/CD , I am setting some variable's value in a Powershell task in CI. During CD I want to access that variable's value to do something , lets say echo.

Is this possible? If so, how?


回答1:


You could write it out to a json/xml file and include that file in your published artifacts of your build defintion. Then read in that file via PowerShell in your release definition.

ConvertTo-Json | Out-File "file.json"
Get-Content "file.json" | ConvertFrom-Json



回答2:


For VSTS itself, it can not persists variables from build to release.

An workaround is store the variable’s value in Variable Group and link the variable group into your release definition. Detail steps as below:

  • During build, you can Add a variable group with the name group-$(Build.BuildId), and store the variable you want to transfer in the variable group.

  • During release, you can get variable groups firstly, and filter the variable under the variable group-$(Build.BuildId). And delete the group group at the end of the release.

Besides, if artifact type is build for your release definition, you can also store the variable value in a file and then publish the file as build artifacts (as Calidus says).




回答3:


Check out the Azure DevOps extension Variable Tools for Azure DevOps Services.

In the "build pipeline" you can create a JSON file using "save variables". This file needs to be published as artifact or with existing artifact.

In the "release pipeline" you can restore the variables using "load variables" from the JSON file.



来源:https://stackoverflow.com/questions/50905024/vsts-can-i-access-the-build-variables-from-release-definition

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