Yaml If 块导致缺少映射
Yaml If blocks causes missing mapping
当构建 运行 不在主分支上时,我正在尝试添加一组可选参数。这个想法是 azure-pipelines-template-variables-private.yml 仅覆盖组中包含的一些参数。
这是我的模板文件:
stages:
- stage: "Tests"
variables:
- group: MyLibrary
${{ if ne(variables['Build.SourceBranchName'], 'master') }}:
- template: azure-pipelines-template-variables-private.yml
此 returns 错误“需要一个映射”
没有 if 块,行为符合预期 - 参数被覆盖。我正在努力理解 if 块是如何工作的。文档展示了如何将变量与组一起使用,以及如何将变量与模板一起使用——但不能同时使用这两者。虽然它似乎可以一起工作,所以我希望 if 语句可以工作。
编辑:有关信息,我包括了变量模板内容:
variables:
- name: MyVar1
value: 'TEST-$(Build.BuildId)'
- name: MyVar2
value: '/Builds/$(BUILD.BUILDID)'
我测试了下面的脚本,它运行良好。希望这对你有帮助:
- stage: build
jobs:
- job: run_build
pool:
vmImage: 'Ubuntu 16.04'
variables:
- group: xxx
- ${{ if ne(variables['Build.SourceBranchName'], 'refs/heads/master') }}:
- template: var.yml
steps:
- script: echo ${{ variables.test }}
当构建 运行 不在主分支上时,我正在尝试添加一组可选参数。这个想法是 azure-pipelines-template-variables-private.yml 仅覆盖组中包含的一些参数。
这是我的模板文件:
stages:
- stage: "Tests"
variables:
- group: MyLibrary
${{ if ne(variables['Build.SourceBranchName'], 'master') }}:
- template: azure-pipelines-template-variables-private.yml
此 returns 错误“需要一个映射”
没有 if 块,行为符合预期 - 参数被覆盖。我正在努力理解 if 块是如何工作的。文档展示了如何将变量与组一起使用,以及如何将变量与模板一起使用——但不能同时使用这两者。虽然它似乎可以一起工作,所以我希望 if 语句可以工作。
编辑:有关信息,我包括了变量模板内容:
variables:
- name: MyVar1
value: 'TEST-$(Build.BuildId)'
- name: MyVar2
value: '/Builds/$(BUILD.BUILDID)'
我测试了下面的脚本,它运行良好。希望这对你有帮助:
- stage: build
jobs:
- job: run_build
pool:
vmImage: 'Ubuntu 16.04'
variables:
- group: xxx
- ${{ if ne(variables['Build.SourceBranchName'], 'refs/heads/master') }}:
- template: var.yml
steps:
- script: echo ${{ variables.test }}