{"id":41184,"date":"2023-02-16T00:00:15","date_gmt":"2023-02-16T07:00:15","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/premier-developer\/?p=41184"},"modified":"2023-02-14T11:28:37","modified_gmt":"2023-02-14T18:28:37","slug":"azure-devops-pipelines-if-expressions-and-conditions","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/premier-developer\/azure-devops-pipelines-if-expressions-and-conditions\/","title":{"rendered":"Azure DevOps Pipelines: If Expressions and Conditions"},"content":{"rendered":"<p><a href=\"https:\/\/www.linkedin.com\/in\/john-folberth\/\" target=\"_blank\" rel=\"noopener\">John Folberth<\/a> continues his series on Azure DevOps Pipelines by taking a deep dive into If Expressions and Conditions.<\/p>\n<hr \/>\n<p><span data-contrast=\"auto\">At this stage in the series we\u2019ve 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.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h2 id=\"toc-hId--594099984\">If Expressions<\/h2>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/devops\/pipelines\/process\/expressions?view=azure-devops#conditionally-run-a-step\" target=\"_blank\" rel=\"noopener noreferrer\"><span data-contrast=\"none\">If expressions<\/span><\/a><span data-contrast=\"auto\">\u00a0are simple and easy enough in YAML pipelines, they are a powerful tool. In my experience I have leveraged if expressions to:<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<ul>\n<li><span data-contrast=\"auto\">Conditionally load templates<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">Dynamically load variables<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">Enable same pipeline for CI\/CD<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><span data-contrast=\"auto\">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.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">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.<\/span><\/p>\n<p>Continues reading the <a href=\"https:\/\/techcommunity.microsoft.com\/t5\/healthcare-and-life-sciences\/azure-devops-pipelines-if-expressions-and-conditions\/ba-p\/3737159\">full post here<\/a> and check out <a href=\"https:\/\/techcommunity.microsoft.com\/t5\/healthcare-and-life-sciences\/bg-p\/HealthcareAndLifeSciencesBlog\/label-name\/YAML%20Pipeline%20Series\" target=\"_blank\" rel=\"noopener\"><span data-contrast=\"none\">the series on the Microsoft Health and Life Sciences Blog<\/span><\/a><span data-contrast=\"auto\">.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2019ve 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 [&hellip;]<\/p>\n","protected":false},"author":582,"featured_media":41185,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[22],"tags":[2571],"class_list":["post-41184","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","tag-azure-devops"],"acf":[],"blog_post_summary":"<p>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\u2019ve 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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts\/41184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/users\/582"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/comments?post=41184"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts\/41184\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/media\/41185"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/media?parent=41184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/categories?post=41184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/tags?post=41184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}