Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Devops multiple Custom conditions

Tags:

azure-devops

I've 2 variables in azure devops

Var1= A,B,C
Var2= 1,2

I need to run a task with the following conditions

Var1=A,B,C & Var2=1,2

Var1=A & Var2=1

From the official doc i can only able to see more simple custom conditions

like

and(succeeded(), in(variables['Var1'], 'A','B','C'))

Here how to include the Var2 using the and condition again more like multiple custom condition.

In a simple C# world we will wrote this like below

(Var1==A || Var1==B || Var1==C) && (Var2==1 || Var2==2)

Update

My final conditions looks like this

( ((Var1==A || Var1==B || Var1==C) && (Var2==2)) || ((Var1==A) &&(Var2==1))) 

How could i achieve this in the custom conditions ?

like image 992
Jayendran Avatar asked Aug 24 '26 14:08

Jayendran


2 Answers

Azure Devops multiple Custom conditions

It seems you want use the matrix variable, it is like every variable, you could use it in this way:

and(succeeded(), in(variables['Var1'], 'A','B','C'), in(variables['Var2'], '1','2'))

Separating variable conditions with commas, and it works fine on my side.

Hope this helps.

like image 101
Leo Liu-MSFT Avatar answered Aug 27 '26 05:08

Leo Liu-MSFT


I have added a custom condition for the classic AzureDevops build pipeline requirement: the build should create an artifact if a branch is a master or release/* branch. Custom condition is mention below: and(succeeded(),or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release/')))

like image 22
KCP Avatar answered Aug 27 '26 03:08

KCP



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!