'In TFS 2017 can you execute all phases on the same agent?

We're using TFS 2017 Update 3 on premise for CI and CD. Our build server has two agents. We only have a few automated releases at the moment but are working on adding more. A typical release has 3 environments and each environment has X phases for the sake of logically separating/grouping activities. For example:

  • Phase 1 - Replace tokens (downloads the artifacts and replaces tokens)
  • Phase 2 - Deploy a database (skips artifact download, uses output from Phase 1, and deploys the db)
  • Phase 3 - Deploy a service (skips artifact download, uses output from Phase 1, and deploys a service)

Up until recently, because we only have few releases, only one release happened at a time and it's worked fine. Tonight I got bit.

What happened was Release 1 started and when it was in Phase 3, Release 2 was queued. Release 2 started Phase 1 on Agent 2 because Agent 1 was being used by Release 1. When Release 2 got to Phase 2, Agent 1 was now free so it performed Phases 2 & 3 on Agent 1. This lead to Phases 2 & 3 of Release 2 operating out of the folder where the release for the previous environment ran thereby resulting in the wrong settings being copied to the target environment. I hope that's clear. Essentially QA settings were copied to PROD.

I had figured that all Phases of an Environment started and finished on the same agent.

So, to achieve "Agent Affinity", is my only option to use 1 Phase? I'll miss the logical separation of steps. I don't see anywhere I can control that.

Thanks in advance for your help.



Solution 1:[1]

Phases should not depend on the output of previous phases. Use a single phase.

You can use task groups to logically group steps together.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daniel Mann