我想对模板有多个依赖关系。有没有办法在参数数组的迭代中建立条件?
parameters:
deps: [Integration, Migration]
jobs:
- deployment: Deploy
displayName: 'Deploy'
dependsOn:
- ${{ each dep in parameters.deps }}:
- ${{ dep }}
condition:
- ${{ each dep in parameters.deps }}:
- in(dependencies.${{ dep }}.result, 'Succeeded', 'Skipped')
environment: QA
strategy:
runOnce:
deploy:
steps:
- bash: |
echo "Deploy dev"
此标记为(第12行,第3行):不需要序列
答案 0 :(得分:0)
该错误是由以下情况引起的:
condition:
- ${{ each dep in parameters.deps }}:
- in(dependencies.${{ dep }}.result, 'Succeeded', 'Skipped')
yaml以上将被评估为:
condition:
- in(dependencies.Integration.result, 'Succeeded', 'Skipped')
- in(dependencies.Migration.result, 'Succeeded', 'Skipped')
条件不能接受一系列表达式。多个表达式应与and
,or
或xor
联接。有关更多信息,请参见here。
您可能需要评估模板之外的条件。
例如,在您的azure-pipelines.yml中添加一个额外的作业以依赖于上述作业:请参见下文:
#azure-pipelines.yml
- job: CheckStatus
dependsOn:
- Integration
- Migration
condition: |
and
(
in(dependencies.Integration.result, 'Succeeded', 'SucceededWithIssues', 'Skipped'),
in(dependencies.Migration.result, 'Succeeded', 'SucceededWithIssues', 'Skipped')
)
steps:
- powershell:
- template: template.yaml
parameters:
deps: CheckStatus
然后,您可以在模板中检查作业 CheckStatus 的状态:
#template.yml
parameters:
deps: CheckStatus
jobs:
- job: secure_buildjob
dependsOn: ${{parameters.deps}}
condition: eq(dependencies.${{ parameters.deps }}.result, 'Succeeded')