首页 > 解决方案 > 将 Azure DevOps Group Vars 作为 Enviroment Vars 访问

问题描述

是否可以在 bash 步骤中将 azure DevOps 变量组中的所有变量作为环境变量访问?

充其量我想要一种方法来访问所有组变量作为python脚本中的环境变量。

因此,yaml我想到了以下类似的内容,但对其他想法持开放态度。没错,我将组中的每个 var 添加为 env 参数,但是yaml如果我想在组中添加新 var,我总是要更新 azure DevOps。就是感觉不太对啊。。。。

pool:
  vmImage: ubuntu-latest
variables:
  - group: myGroup

stages:
  - stage: test
    jobs:
      - job: test
        displayName: Test
        steps:
          - bash: |
              echo $path.myGroup
            group:
              - myGroup

标签: bashazure-devopsyamlenvironment-variablesazure-pipelines

解决方案


这是不可能的。但是,您可以尝试使用azure CLI来获取组内非机密变量的名称和值。它不会为您返回秘密变量的值,但是对于它们,您仍然必须显式地映射它们。

如果你这样做:

pool:
  vmImage: ubuntu-latest


stages:
  - stage: test
    jobs:
      - job: test
        displayName: Test
        variables:
        - group: myGroup
        steps:
          - bash: |
              echo 'You have all non secret variables ampped to env variables`
              echo `You can use Azure Cli to get all names of the mapped variables from variables group`

您将获得所有非秘密变量的映射。

你也可以使用

        variables:
        - group: myGroup

在顶层实现相同,但随后您将在所有工作中映射它。


推荐阅读