Azure DevOps: Use VSTS conditions to control build or release flow


I was asked recently about how to use Visual Studio Team Services (VSTS) conditions to run different tasks dependent on the outcome of previous tasks (effectively branch the behaviour in a release). The scenario was:

  • Perform a series of release tasks.
  • Validate the release using a manual intervention task.
  • If the manual intervention was rejected (there was a problem) then run tasks to rollback the release.
  • If the manual intervention was resumed (the release was accepted) carry on.

So, how do you reflect this in a release (and note this can also be applied to a build)?

As an example I have created a release, using PowerShell tasks for simplicity, as shown below:

The first agent phase is uninteresting and simply represents the running of release tasks (a single PowerShell task here but of course it could be any number of tasks performing any activity):

I’ve then added an agentless phase and within that added a manual intervention task. The release will wait for the specified groups and/or people to state that the release should resume or be rejected:

Next I’ve added another agent phase that I’ve called Rejection flow, and at the agent level itself I have set the Run this phase setting to Only when a previous phase has failed:

This means that any tasks in this phase (I’ve only added one called Rollback activity) will be run only when the phase is run, which is when the manual intervention is rejected. No need to set conditions on each task within the phase.

Finally I’ve added another agent phase that I’ve called Resumption flow. This is set to run Only when all previous phases have succeeded:

This means that any tasks in this phase will be run only when the manual intervention is resumed. Again each task in the phase doesn’t need to have conditions set.

Therefore, when running this release, if I reject at the manual intervention:

Then the Rejection flow agent phase is run, but not the Resumption flow agent phase:

And vice versa, if I resume at the manual intervention then only the Resumption flow is run:

In summary VSTS provides a simple means of creating conditional flows in builds and releases, and in this case without needing to use custom conditions.

Giles Davies

Comments (0)

Skip to main content