如何在VSTS vNext构建定义中的变量内引用变量? [英] How to reference a variable within a variable in VSTS vNext build definition?

查看:75
本文介绍了如何在VSTS vNext构建定义中的变量内引用变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在新的VSTS脚本系统中,如何在变量中引用变量?

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

例如:

RemoteMachineFqdn:somemachinename.somedomain

RemoteMachineFqdn: somemachinename.somedomain

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

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

在上述示例中,假设存在一些任务都使用带有给定变量的CMD和Powershell脚本.我尝试通过从环境中引用变量的值来使用变量,但是它不适用于两种情况,因为%variable%仅在CMD和$ env:variable中起作用-仅在Powershell中.

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?

推荐答案

您正在寻找的是

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

此示例在taskcontext的变量服务中设置一个变量.第一个任务可以设置一个变量,随后的任务可以使用该变量.该变量作为环境变量公开给以下任务.

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.

这篇关于如何在VSTS vNext构建定义中的变量内引用变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆