Azure DevOps Pipelines: If Expressions and Conditions

Developer Support

John Folberth continues his series on Azure DevOps Pipelines by taking a deep dive into If Expressions and Conditions.

At this stage in the series we’ve talked about tasks, jobs, stages, how to template them, and how to leverage environments in variables. This post will attempt to cover some basics around using if and conditions in your YAML Pipelines. 

If Expressions

If expressions are simple and easy enough in YAML pipelines, they are a powerful tool. In my experience I have leveraged if expressions to: 

  • Conditionally load templates 
  • Dynamically load variables 
  • Enable same pipeline for CI/CD 

The key to unlocking their power is the understanding that an if expression will evaluate at pipeline compilation. This means the pipeline has to leverage known values to apply the logic within. We should not use an if expression when relying on the output of another task/job, the status of another job, or a variable that is updated during pipeline execution. 

The other side of this, since the statement is evaluated at pipeline compilation time, is that we will not load any unnecessary templates into our pipelines. As opposed to conditions, which will we cover next, templates will not appear in the expanded pipeline YAML file. This leads to a cleaner and more secure experience since only what will be executed will appear in the pipeline logs.

Continues reading the full post here and check out the series on the Microsoft Health and Life Sciences Blog.