【问题标题】:Access Azure DevOps Group Vars as Enviroment Vars作为环境变量访问 Azure DevOps Group Vars
【发布时间】:2021-09-13 09:54:41
【问题描述】:

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

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

所以我想到了下面的yaml,但对其他想法持开放态度。没错,我将组中的每个 var 添加为 env 参数,但是如果我想在组中添加新的 var,我总是要更新 azure DevOps yaml。这只是感觉不对....

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

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

【问题讨论】:

    标签: bash azure-devops yaml environment-variables azure-pipelines


    【解决方案1】:

    这是不可能的。但是,您可以尝试使用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
    

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

    【讨论】:

    • 谢谢?,就我而言,我还想访问秘密变量。我会看看 azure CLI,看起来管道有隐藏的力量?
    猜你喜欢
    • 2020-04-02
    • 1970-01-01
    • 2023-02-04
    • 1970-01-01
    • 2020-01-15
    • 1970-01-01
    • 2020-03-25
    • 2019-11-08
    • 2021-04-28
    相关资源
    最近更新 更多