Search code examples
azure-devopsyamlazure-pipelinespipelinerelease

Azure Devops Yaml release pipeline: pipeline level conditional expression


I'm trying to do something that seems pretty straightforward to me, I keep getting a not very useful mapping error when I try to run it (compile time error): "A mapping was not expected"

The error points to the line "${{ if eq(parameters.dev_vault, '001') }}:" below

Here is my yaml pipeline:

parameters:
  - name: dev_vault
    displayName: "Dev Vault Id (Same as Database Id)"
    type: string
    default: 001

...

variables:
  - template: vars/global.yml  
  - name:  devDatabaseName
    value: 
      ${{ if eq(parameters.dev_vault, '001') }}:
        "DEV_PSP"
      ${{ else }}:
        "DEV${{parameters.dev_vault}}_PSP"
...

Am I trying to do something that is not supported?


Solution

  • Please try this:

    parameters:
      - name: dev_vault
        displayName: "Dev Vault Id (Same as Database Id)"
        type: string
        default: 001
    
    ...
    
    variables:
      - template: vars/global.yml  
      - name:  devDatabaseName
        ${{ if eq(parameters.dev_vault, '001') }}:
          value: "DEV_PSP"
        ${{ else }}:
          value: "DEV${{parameters.dev_vault}}_PSP"
    ...