I would like to have if condition under parameters in Azure pipeline yml file. Please find my code below:
I want to show iPhone 13, iPhone 13 Pro, iPhone SE if product is selected as phone. And show Macbook Pro, Macbook Air if product is selected as computer and so on. But I'm getting an below error if I try to add the conditional statement inside parameters
Pipeline Error:
Encountered error(s) while parsing pipeline YAML:
/azure-pipeline.yml (Line: 17, Col: 5): A template expression is not allowed in this context
/azure-pipeline.yml (Line: 21, Col: 5): A template expression is not allowed in this context
Pipeline code:
trigger:
- none
parameters:
- name: product
displayName: Select Product
type: string
default: phone
values:
- phone
- computer
- watch
- name: selectProduct
displayName: Select Product
type: string
${{ if eq(parameters.product, 'phone') }}:
values:
- iPhone 13
- iPhone 13 Pro
- iPhone SE
${{ if eq(parameters.product, 'computer') }}:
values:
- Macbook Pro
- Macbook Air
${{ if eq(parameters.product, 'watch') }}:
values:
- Apple Watch Series 7
- Apple Watch SE
Can someone please suggest how can I handle this in azure pipeline, incase if condition is not supported under parameters section - what's the alternative approach.
Any help would he much appreciated. Thanks!
Note: I want to show this option before pipeline job trigger/submit. This options should pop up when I click Run Pipeline button.