Skip to content

Instantly share code, notes, and snippets.

@almmechanics
Last active April 15, 2019 09:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almmechanics/7636f6c8d91ab8d08c16eaf6af500731 to your computer and use it in GitHub Desktop.
Save almmechanics/7636f6c8d91ab8d08c16eaf6af500731 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.

Note: There are some differences between Build and Release Pipelines configurations, 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 an Azure DevOps 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