0

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

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"

这个被标记为 (Line: 12, Col: 3): A sequence was not expected

4

1 回答 1

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。请参阅此处了解更多信息。

您可能必须评估模板外的条件。

例如,在 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')
      
于 2020-07-15T08:32:53.430 回答