0

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?

Ganesh Somani
  • 2,280
  • 2
  • 28
  • 37
  • You can try the following ```variables: ${{ if eq(parameters.selectConfiguration, 'Debug') }}: value: Debug ${{ else }}: value: Release ``` – Dilly B Mar 14 '22 at 06:01

2 Answers2

1

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
GeralexGR
  • 2,973
  • 6
  • 24
  • 33
-2

In YAML pipeline, you can not use the if...else expression to assign different values to a variable in different conditions.

You can only use the if expression to determine a variable which has one specified value can be available in the specified condition. See "Conditionally assign a variable".

The if...else expression can be used to:

Bright Ran-MSFT
  • 5,190
  • 1
  • 5
  • 12