gpt4 book ai didi

Azure DevOps PowerShell - 我可以为库组变量构建变量字符串吗

转载 作者:行者123 更新时间:2023-12-03 01:15:28 24 4
gpt4 key购买 nike

PowerShell 5.1
组中的库变量名称:test.DEV
Azure DevOps 参数值:config

我想构建变量名称 test.DEV,然后获取存储在 Azure DevOps 的库变量中的值。对于输出,我获取的是变量名称而不是变量值。这可能吗?

steps:
- powershell: |
$myVar = "test.${{ parameters.config }}"
'$($myVar)'

输出:

test.DEV

需要 test.DEV 的值而不是变量名称

最佳答案

根据您的描述,您需要在 Azure Pipeline 中使用嵌套变量。

示例:$($myVar)

恐怕Azure pipeline中没有内置方法可以实现这一点。

为了满足您的要求,您可以使用扩展程序中的变量集任务:Variable Toolbox .

这是一个例子:

变量组:

enter image description here

管道 YAML:

parameters:
- name: config
type: string

pool:
vmImage: ubuntu-latest
variables:
- group: test
steps:
- task: VariableSetTask@3
inputs:
variableName: 'myVar'
value: '$(test.${{ parameters.config }})'
- powershell: |

echo $(myVar)

结果:

enter image description here

关于Azure DevOps PowerShell - 我可以为库组变量构建变量字符串吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75062339/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com