如何使用字符串和另一个变量值在 VSTS 构建中引用变量?
How can I reference a variable in a VSTS build using a string and another variable value?
我希望在 VSTS 中使用字符串和另一个变量的值来引用自定义变量来创建我想要的变量的键。
我拥有的是特定于每个环境的变量,我想在任务中引用正确的变量。因此,在我的屏幕截图中,我尝试根据环境变量是 "DEV" 还是 "QA" 来引用变量 MobileCenter.GroupID.DEV 或 MobileCenter.GroupID.QA 的值。我在屏幕截图中显示的内容似乎不起作用。
你不能那样做。
如果没有更多上下文很难说,但我认为我们有一个 X-Y 问题——你问的是如何实施解决方案 Y,但你应该问的是如何解决问题 X。
您可能想要做的是使用发布定义而不是构建定义,并将事情分解为管道的各个阶段——您可以为 "Dev" 和一个 "QA",每个都有不同的变量值。
是的,可以将一个变量的值用于另一个变量。
您可以在每个发布环境中使用格式 $(MobileCenter.GroupID.$(Release.EnvironmentName))
。然后你可以针对不同的环境获取不同的值。
而变量$(Release.EnvironmentName)
是一个predefined variable,它可以获取你的环境名称,如DEV、QA等,所以你不需要在你的发布定义中定义它。
你可以做点什么,看看marina-msft's answer in Is there a way to do nested variables in VSTS Release Management。
The two approaches you listed can work good. And VSTS release support nested variables.
Except define a variable in release definition (or environment variable) or use it directly, you can add the variable CodeNetworkShare1=$(CodeNetworkShare.$(Release.EnvironmentName))
directly in variable group. Then in your release definition, it can use applied with different values for different environment names.
我希望在 VSTS 中使用字符串和另一个变量的值来引用自定义变量来创建我想要的变量的键。
我拥有的是特定于每个环境的变量,我想在任务中引用正确的变量。因此,在我的屏幕截图中,我尝试根据环境变量是 "DEV" 还是 "QA" 来引用变量 MobileCenter.GroupID.DEV 或 MobileCenter.GroupID.QA 的值。我在屏幕截图中显示的内容似乎不起作用。
你不能那样做。
如果没有更多上下文很难说,但我认为我们有一个 X-Y 问题——你问的是如何实施解决方案 Y,但你应该问的是如何解决问题 X。
您可能想要做的是使用发布定义而不是构建定义,并将事情分解为管道的各个阶段——您可以为 "Dev" 和一个 "QA",每个都有不同的变量值。
是的,可以将一个变量的值用于另一个变量。
您可以在每个发布环境中使用格式 $(MobileCenter.GroupID.$(Release.EnvironmentName))
。然后你可以针对不同的环境获取不同的值。
而变量$(Release.EnvironmentName)
是一个predefined variable,它可以获取你的环境名称,如DEV、QA等,所以你不需要在你的发布定义中定义它。
你可以做点什么,看看marina-msft's answer in Is there a way to do nested variables in VSTS Release Management。
The two approaches you listed can work good. And VSTS release support nested variables.
Except define a variable in release definition (or environment variable) or use it directly, you can add the variable
CodeNetworkShare1=$(CodeNetworkShare.$(Release.EnvironmentName))
directly in variable group. Then in your release definition, it can use applied with different values for different environment names.