简体   繁体   English

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

[英]How to access same variable from different variable group Azure Pipeline?

I am using azure-pipelines.yaml to build multiple stages each stage having a same variable ie var_key but different value in each stage for this I have different Azure Library groups我正在使用 azure-pipelines.yaml 来构建多个阶段,每个阶段都有相同的变量,即 var_key 但每个阶段的值不同,为此我有不同的 Azure 库组

  1. dev_group开发组
  2. qa_group qa_group

azure-pipelines.yaml azure-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)

this is giving me an error, is there an correct way of doing this.这给了我一个错误,是否有正确的方法来做到这一点。

In the future, please refer to the YAML schema documentation before you ask a question about an error with YAML.将来,在您询问有关 YAML 错误的问题之前,请参阅YAML 架构文档

A quick review of that document shows that this:对该文件的快速审查表明:

variables:
  group: group1, group2, group3

is not correct syntax.是不正确的语法。

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.您还可以包含模板中的变量。

Extrapolating from that,由此推断,

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

Following the schema is critical when writing YAML configuration documents.在编写 YAML 配置文档时,遵循架构至关重要。 It is whitespace sensitive, so be sure you are indenting properly.它对空格敏感,因此请确保正确缩进。 I recommend using an editor such as VS Code with the Azure Pipelines YAML extension installed to help catch problems like this.我建议使用安装了 Azure Pipelines YAML 扩展的 VS Code 等编辑器来帮助捕获此类问题。

Beyond that, to use a variable group only within a stage, you reference it within the stage block:除此之外,要仅在阶段中使用变量组,请在stage块中引用它:

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

Again, read the schema documentation.再次阅读架构文档。 This is all very well documented.这都是有据可查的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM