【问题标题】:Azure YAML pipeline: find variable in group dynamicallyAzure YAML 管道:动态查找组中的变量
【发布时间】:2020-11-16 14:27:17
【问题描述】:

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

我可以使用$(myVar) 引用组变量。但是现在我需要动态引用一个给定名称的变量。

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

这有可能实现吗?

【问题讨论】:

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


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-20
      • 2021-11-23
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      • 1970-01-01
      相关资源
      最近更新 更多