Azure YAML管道:动态查找组中的变量

时间:2020-07-27 09:18:05

标签: azure azure-devops yaml azure-yaml-pipelines

我有一个Powershell脚本,该脚本在发布阶段在我的YAML管道中执行。

我可以使用$(myVar)引用组变量。但是,现在我需要动态地给定变量名称来引用它。

例如,如果我有字符串“ myVar”,我想在变量组中搜索名为“ myVar”的变量并获取其值。

这有可能实现吗?

1 个答案:

答案 0 :(得分:1)

最后,我这样做了。首先,我为Powershell安装了Devops模块,以便可以通过devops api获取组变量:

 Add-AzureDevOpsAccount    -OrganisationName "myor"   -ProjectName "myproj"   -Token "mytoken"

Write-Host -ForegroundColor DarkGreen "Getting variables group based on name"
$group = Get-AzureDevOpsVariableGroup -SearchString "dev"

然后根据其名称获取变量:

$tokenValue = $group.variables | Select-Object -ExpandProperty $someName | Select-Object -ExpandProperty Value