Mitul Patel
Mitul Patel

Reputation: 66

How to add custom pipeline in azureDevops

i have create CI/CD pipeline in azureDevops. i need to add custom condition for when only previous task succeeded then it will execute.

so please help me what i have to write in Custom condition ?

I have attached below screen short where i need to add some custom condition.

enter image description here

Upvotes: 1

Views: 332

Answers (3)

Mitul Patel
Mitul Patel

Reputation: 66

i have found some custom condition which has fulfill my desire task.

in(variables['Agent.JobStatus'], 'Failed', 'Succeeded', 'SucceededWithIssues')

in above custom condition for if the prev task will 'failed' or 'succeeded' next task will executed.

Upvotes: 0

Leo Liu
Leo Liu

Reputation: 76760

i need to add custom condition for when only previous task succeeded then it will execute.

There is directly option Only when all previous tasks have succeeded, which is used to determine if all the previous tasks have succeeded.

If you want to give the condition that just when only the one previous task succeeded, there is no such out of box option to use. We could use the workaround that Napoleon answered:

write the result of the previous task to a variable and then check that variable in your condition

In addition, I posted this answer to emphasize the choice of conditions, we need use always() not succeeded() or failed(). That because the syntax of condition is for all previous steps/jobs:

Check the document Conditions for some more details.

For example:

I add three tasks in my pipeline:

  1. Command line-Intentionally let it run failed

  2. Run Inline Powershell-create a variable, assign it a value.

     Write-Host "##vso[task.setvariable variable=TaskStatus;]Succeeded"
    
  3. Command line-Custom Condition checking that variable.

     and(always(), eq(variables['TaskStatus'], 'Succeeded'))
    

enter image description here

enter image description here

If we use the condition succeeded() or failed(), whether its execution is still affected by all previous task execution results (First command line task.)

Hope this helps.

Upvotes: 1

Napoleon Ike Jones
Napoleon Ike Jones

Reputation: 565

You could write the result of the previous task to a variable and then check that variable in your condition.

Upvotes: 0

Related Questions