Skip to content

Instantly share code, notes, and snippets.

@almmechanics
Created April 12, 2019 11:54
Show Gist options
  • Save almmechanics/4e03c2eeb33ed09c3f026c37aafd1239 to your computer and use it in GitHub Desktop.
Save almmechanics/4e03c2eeb33ed09c3f026c37aafd1239 to your computer and use it in GitHub Desktop.
Azure DevOps conditional build/release phases

Azure DevOps conditional build/release phases

A Variable can be used to enable/disable elements of build/release pipelines in Azure DevOps. This GIST shows how this can be implemented within a pipeline.

Creating the Variable

Within the Variables tab create a new variable for this toggle, and set this to a suitable default.

The following example creates a variable Deploy.Arm that defaults to false that can be overridden at the creation of the queue. There are some simple differences between Build and release Pipelines, so examples of both are shown here.

Build Pipeline Scope

The configuration for a Build pipeline would be:

Field Value
Name Deploy.Arm
Value False
Secret False
Settable at queue time true

Release Pipeline Scope

The configuration for a Release pipeline would be:

Field Value
Name Deploy.Arm
Value False
Secret False
Scope Depends on usage
Settable at release time true

Using the Variable to toggle an Agent Phase

To allow the Deploy.Arm variable to toggle an agent phase then apply the following changes to the top level of the Agent Job.

Expand the Additional Options section, and update the following fields:

Field Value
Run this job Custom condition using variable expressions
Variable expression eq(variables['Deploy.Arm'],'true')

Using the Variable to toggle a Azure DevOps Task

To allow the Deploy.Arm variable to toggle a task then apply the following changes to the task.

Expand the Control Options section, and update the following fields:

Field Value
Run this task Custom conditions
Custom condition eq(variables['Deploy.Arm'],'true')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment