0

I want to have multiple dependencies over a template. Is there a way to establish condition over the iteration of a parameter array ?

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"

This one is marked as (Line: 12, Col: 3): A sequence was not expected

Zahid
  • 91
  • 1
  • 10
  • 1
    Hi `Condition` cannot accept a sequence of expressions. You may need to check the status of dependencies jobs outside the template. Please check out below example. – Levi Lu-MSFT Jul 17 '20 at 08:52

1 Answers1

0

The error is caused by below condition:

condition: 
- ${{ each dep in parameters.deps }}:
  - in(dependencies.${{ dep }}.result, 'Succeeded', 'Skipped')

Above yaml will be evaluated to :

condition: 
  - in(dependencies.Integration.result, 'Succeeded', 'Skipped')
  - in(dependencies.Migration.result, 'Succeeded', 'Skipped')

Condition cannot accept a sequence of expressions. Multiple expressions should be joined with and , or or xor. See here for more information.

You might have to evaluate the condition outside the template.

For example, add an additional job in your azure-pipelines.yml to depend on the above jobs: See below:

  #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

Then you can just check the status of job CheckStatus in the template:

#template.yml
parameters:
  deps: CheckStatus
  
jobs:
- job: secure_buildjob
  dependsOn: ${{parameters.deps}}
  condition: eq(dependencies.${{ parameters.deps }}.result, 'Succeeded')
      
Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43