当构建运行不在 master 分支上时,我试图添加一组可选参数。这个想法是 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
这将返回错误“Expected a mapping”
在没有 if block 的情况下,行为符合预期 - 参数被覆盖。我正在努力理解 if block 是如何工作的。文档展示了如何将变量与组一起使用,以及如何将变量与模板一起使用——但不能同时使用这两者。虽然它似乎可以一起工作,但我希望 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-devops - Yaml If block 导致缺少映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62115922/