Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure multistage pipelines: conditionally skip one stage but not the next

I have an Azure multi-stage CI/CD pipeline. It has stages for Test and UAT deployment.

I want the UAT release to run if Test succeeds or is skipped, but not if it fails.

I can't. Whatever I try, if Test is skipped, UAT is also skipped. Unless I use always(), but then UAT will run even if Test fails.

  ...
  - stage: Test
    condition: and(succeeded(), ne(variables['build.sourceBranchName'], 'DoUAT')) # Skip for UAT deployment tests
    ...

  - stage: UAT
    condition: and(succeeded(), in(variables['build.sourceBranchName'], 'master', 'DoUAT')) # Only deploy off master branch and branch to test UAT deploys.
    ...

How do I skip one stage but not the next one?

What I get vs what I want

like image 956
EdH Avatar asked Dec 13 '22 09:12

EdH


1 Answers

You can use not(failed('Test')) condition, please try below condition.

- stage: UAT
    condition: and(not(failed('Test')), in(variables['build.sourceBranchName'], 'master', DoUAT')) # Only deploy off master branch and branch to test UAT deploys.
    ...

I tested and it worked, check below screenshot.

enter image description here

like image 57
Levi Lu-MSFT Avatar answered Dec 28 '22 11:12

Levi Lu-MSFT