Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple checks with if else and or in yaml

I am trying to utilize one YAML file for multiple environments with different configuration settings.

Below is the yaml example:

parameters:
- name: environment
  displayName: Build Environment
  type: string
  default: Staging
  values:
  - Staging
  - Release
  - Production

variables: 
  - name: certificatename
  ${{ if eq(parameters.environment, 'Staging') }}:
  value: 'cert1.p12'
  ${{ if eq(parameters.environment, 'Release') }}:
  value: 'cert2.p12'

Is there a way to club release and prod in one go?

like ${{ if eq(parameters.environment, 'Release'), eq(parameters.environment, 'Production') }}: however, I keep getting errors. If anyone knows of any way to the club this statement, would appreciate the input.

like image 594
topgun Avatar asked Dec 01 '25 22:12

topgun


1 Answers

You can use the in operator instead of eq to check for multiple values

${{ if in(parameters.environment, 'Release', 'Production') }}:

documentation : https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops#in

enter image description here

like image 121
Rimaz Mohommed Avatar answered Dec 04 '25 12:12

Rimaz Mohommed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!