在多阶段Azure DevOps Yamls上迭代依赖于依赖和条件的操作

时间:2020-07-15 00:57:19

标签: azure-devops yaml multistage-pipeline

我想对模板有多个依赖关系。有没有办法在参数数组的迭代中建立条件?

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行):不需要序列

1 个答案:

答案 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')

条件不能接受一系列表达式。多个表达式应与andorxor联接。有关更多信息,请参见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')