Search code examples
azure-devopsazure-pipelinesazure-pipelines-yaml

Job Conditions in Azure Pipelines


In my yaml pipeline I have multiple jobs which are dependent on each other. However in one of the jobs when I define the condition, I am getting the following error:

Unexpected symbol: ')'. Located at position 53 within expression: and(not(or(failed('Unittests'), canceled('Unittests'))), not(canceled('Check_Requirements'))). For more help, refer to https://go.microsoft.com/fwlink/?linkid=842996 Job Condition Error

This is how I defined the job which is showing the error:

  - job: Security_Check
displayName: "Security Check"
dependsOn:
  - Check_Requirements
  - Unittests
condition: and(not(or(failed('Unittests'), canceled('Unittests'))), not(canceled('Check_Requirements')))
pool:
  name: "Basic_Pool_Ubuntu"
variables:
  - name: foundVuls
    value: $[ dependencies.Check_Requirements.outputs['CheckVuls.foundVul'] ]
  - name: Artifact.Folder
    value: "artifacts"

I want the Job to run when the Job 'Unittests' has not failed or cancelled and the job 'Check_Requirement' has not failed.

Does anyone know what am I doing wrong here. I tried multiple ways to define this condition but always got the "Unexpected symbol: ')'" Error


Solution

  • Based on your YAML sample, I can reproduce the same issue.

    enter image description here

    I want the Job to run when the Job 'Unittests' has not failed or cancelled and the job 'Check_Requirement' has not failed.

    To meet your requirement, you can use the following condition:

    condition: and(notIn(dependencies.Unittests.result, 'failed', 'canceled'), ne(dependencies.Check_Requirements.result, 'canceled'))
    

    YAML Sample:

    - job: Security_Check
      displayName: "Security Check"
      dependsOn:
        - Check_Requirements
        - Unittests
      condition: and(notIn(dependencies.Unittests.result, 'failed', 'canceled'), ne(dependencies.Check_Requirements.result, 'canceled'))
      pool:
        name: "Basic_Pool_Ubuntu"
      variables:
        - name: foundVuls
          value: $[ dependencies.Check_Requirements.outputs['CheckVuls.foundVul'] ]
        - name: Artifact.Folder
          value: "artifacts"