azure-devops - Azure DevOps YAML“每个”语法
问题描述
我正在为each
YAML 模板中关键字的语法而苦苦挣扎。
本质上,我将作业列表传递给模板。模板应该执行这些作业,过滤掉不需要的变量组。
template.yml:
parameters:
- name: DeployJobs
type: jobList
jobs:
- ${{ each job in parameters.DeployJobs }}:
${{ if job.variables }}:
variables:
- ${{ each var in job.variables }}:
- ${{ each pair in var }}:
${{ if ne(pair.value, 'var-group-blue') }}:
- group: ${{ pair.value }}
azure-pipelines.yml:
jobs:
- template: template.yml
parameters:
DeployJobs:
- deployment: mydeployjob
variables:
- group: var-group-blue # the template should filter out this var group
- group: var-group-green
...
但是我收到了编译错误Expected a mapping
并且Object reference not set to an instance of an object.
在线:
- group: ${{ pair.value }}
任何人都可以就我可能遗漏的语法或缩进提供建议吗?
解决方案
我想到了。我在if
条款上遗漏了一个破折号。何时使用破折号以及缩进多少的细节非常神秘,并且在文档中没有记录。
工作解决方案:
# template.yml
parameters:
- name: DeployJobs
type: jobList
jobs:
- ${{ each job in parameters.DeployJobs }}:
${{ if job.variables }}:
variables:
- ${{ each var in job.variables }}:
- ${{ each pair in var }}:
- ${{ if ne(pair.value, 'var-group-blue') }}:
- group: ${{ pair.value }}
# azure-pipelines.yml
jobs:
- template: template.yml
parameters:
DeployJobs:
- deployment: mydeployjob
variables:
- group: var-group-blue # the template should filter out this var group
- group: var-group-green
...
推荐阅读
- google-apps-script - “抱歉,发生内部错误,您的请求未完成。” 尝试共享项目时
- java - 编写一个迭代 Map 的方法,查找包含值的 Object 条目,将此 Object 添加到新集合中,然后返回该集合
- python - 检查输入的值是否存在于列表中
- r - R 使用 person.id 将两行合二为一
- node.js - 安装 nvm 和其他 git 的东西一直拒绝授予权限,无论是否以 root 身份
- reactjs - 不使用提供的密钥道具做出反应
- windows-store-apps - UWP 应用程序:版本号:修订号
- android - Firebase 与 Flutter Android 的集成不起作用
- node.js - 我怎样才能根据高度页或 div 计算行数表?
- c - C99/C11 中的两个结构可以别名吗?