Search code examples
azureazure-devopscontinuous-integrationcicdazure-yaml-pipelines

Azure YAML if-else always fail


I am recently doing an CI/CD setup using Azure. The goal is to have the developer select the type of build to be created i.e Staging / Prod.

Thanks to How to write if else condition in Azure DevOps Pipeline, I have added following code -

parameters:
- name: selectConfiguration
displayName: Select build configuration
type: string
default: Debug
values:
 - Debug
 - Release

variables:
- name: config
${{ if eq(variables['parameters.selectConfiguration'], 'Debug') }}:
  value: Debug
${{ else }}:
  value: Release

This gives me the following result -

enter image description here

But no matter what I select in this radio group, it always run the else block. i.e. the if-else always fails. Any help to understand what I am doing wrong here?


Solution

  • Try the below, it should work. I am using the same logic to switch between different agent pools.

    variables:
      ${{ if eq(parameters.selectConfiguration, 'Debug') }}: 
        config: Debug
      ${{ else }}:
        config: Release