How to reference a variable within a variable in VSTS vNext build definition?

纵饮孤独 提交于 2020-02-04 01:39:34

问题


How is it possible to reference a variable within a variable in the new scripting system of VSTS?

e.g:

RemoteMachineFqdn: somemachinename.somedomain

RemoteMachineUncPath: \\$(RemoteMachineFqdn)\c$\

In the aforementioned example, assume there are tasks that both use CMD and Powershell scripts with the given variables. I tried using the the variables by referencing their values from the environment but it does not work for both scenarios since %variable% works only in CMD and $env:variable - only in Powershell.

What is the standard way to do it?


回答1:


What you are looking for is Logging Commands. To invoke a logging command, simply emit the command via standard output. For example, from a PowerShell task:

##vso[task.setvariable variable=testvar;]testvalue

This example sets a variable in the variable service of taskcontext. The first task can set a variable, and following tasks are able to use the variable. The variable is exposed to the following tasks as an environment variable.



来源:https://stackoverflow.com/questions/37101743/how-to-reference-a-variable-within-a-variable-in-vsts-vnext-build-definition

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