azure-devopsyamlazure-pipelines

yaml pipeline job condition throwing unrecognized value error


I have a pipeline in Azure DevOps which build my iOS application I want to separate the environments and what I am building for by jobs and conditions. I have set up the initial parameter select:

parameters:
  - name: Environment
    displayName: "Environment"
    type: string
    default: Dev
    values:
    - Dev
    - Live
  - name: Build
    displayName: "Build"
    type: string
    default: iPhone
    values:
    - iPhone
    - iPhoneSimulator

and then where I set up the different job I have added a condition:

      - job:
        condition: and(succeeded(), eq(${{ parameters.Build }}, iPhone))
        steps:
          - checkout: none

When I try to run this I get the following error:

An error occurred while loading the YAML build pipeline. Unrecognized value: 'iPhone'. Located at position 21 within expression: and(succeeded(), eq(iPhone, iPhone)).

Solution

  • iPhone is not a valid literal. Since parameter expansion happens before condition evaluation, you need to make sure that your condition has proper syntax after parameter expansion by enclosing string literals in single quotes:

    and(succeeded(), eq('${{ parameters.Build }}', 'iPhone'))