Nav*_*mar 1 yaml azure azure-devops azure-pipelines azure-pipelines-release-pipeline
我正在使用 azure-pipelines.yaml 来构建多个阶段,每个阶段都有相同的变量,即 var_key 但每个阶段的值不同,为此我有不同的 Azure 库组
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)
Run Code Online (Sandbox Code Playgroud)
这给了我一个错误,是否有正确的方法来做到这一点。
将来,在您询问有关 YAML 错误的问题之前,请参阅YAML 架构文档。
对该文件的快速审查表明:
variables:
group: group1, group2, group3
Run Code Online (Sandbox Code Playgroud)
是不正确的语法。
要包括变量组,请切换到以下序列语法:
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.
Run Code Online (Sandbox Code Playgroud)
您还可以包含模板中的变量。
由此推断,
variables:
- group: group1
- group: group2
- group: group3
Run Code Online (Sandbox Code Playgroud)
在编写 YAML 配置文档时,遵循架构至关重要。它对空格敏感,因此请确保正确缩进。我建议使用安装了 Azure Pipelines YAML 扩展的 VS Code 等编辑器来帮助捕获此类问题。
除此之外,要仅在阶段中使用变量组,请在stage块中引用它:
stages:
- stage: Foo
variables:
- group: DEVgroup
Run Code Online (Sandbox Code Playgroud)
再次阅读架构文档。这都是有据可查的。
| 归档时间: |
|
| 查看次数: |
1464 次 |
| 最近记录: |