如何从不同的变量组 Azure Pipeline 访问相同的变量?

How to access same variable from different variable group Azure Pipeline?

我正在使用 azure-pipelines.yaml 构建多个阶段,每个阶段都有相同的变量,即 var_key 但每个阶段的值不同为此我有不同的 Azure 库组

  1. dev_group
  2. qa_group

蔚蓝-pipelines.yaml

name: $(Date:yyyyMMdd)$(Rev:.r)

pr:
  branches:
    include:
    - develop
    - master

trigger:
  branches:
    include:
    - develop
    - master

variables:
  group: group1, group2, group3
  BuildNumber: $(Build.BuildNumber)

stages:
  - stage: debug
    jobs:
      - job: DebugConditions
        pool: 
          vmImage: 'ubuntu-latest'
        steps:
          - bash: echo $(group1.var_key)

   - stage: dev
    jobs:
      - job: DevConditions
        pool: 
          vmImage: 'ubuntu-latest'
        steps:
          - bash: echo $(group2.var_key)

这是一个错误,有没有正确的方法。

以后,在询问有关 YAML 错误的问题之前,请参阅 YAML schema documentation

对该文件的快速回顾表明:

variables:
  group: group1, group2, group3

语法不正确。

To include variable groups, switch to this sequence syntax:

 variables:
 - name: string  # name of a variable   value: string # value of the variable
 - group: string # name of a variable group You can repeat name/value pairs and group.

You can also include variables from templates.

据此推断,

variables:
- group: group1
- group: group2
- group: group3

编写 YAML 配置文档时,遵循模式至关重要。它对空格敏感,因此请确保缩进正确。我建议使用安装了 Azure Pipelines YAML 扩展的 VS Code 等编辑器来帮助解决此类问题。

除此之外,要仅在阶段中使用变量组,您可以在 stage 块中引用它:

stages: 
- stage: Foo
  variables:
  - group: DEVgroup

再次阅读架构文档。这一切都有很好的记录。