Date posted: 06 Dec 2020, 3 minutes to read

Missing stages in Azure DevOps YAML Pipelines

Alt. title: approval to an environment blocks the whole pipeline

Sometimes you find out about something and feel rather stupid. This one is one of the reasons YAML pipelines often feel like you need a magic incantation to get things working the correct way. Since this took me way to long to figure out, I’m writing about it here to hopefully safe someone else a lot of time (probably my future self 😁). I have bumped into these incantations before: using different CI/CD systems seems to make me forget them 🤔. Stupid image of a T-Rex statue

Photo by Dan Meyers on Unsplash

The premise

I was working on a multi-stage pipeline in Azure DevOps using YAML files. In the beginning I only had the Build part of my pipeline to build the solution. Wanting to deploy it, I added deployment phases to my setup. To get them working, I made the mistake to see them as specific jobs. [TLDR: the are not]:

jobs:
 - job: Build
   steps:
     - task: SomeTask

 - deployment: DeployTest
   displayName: Deploy to test
   environment: Test
   dependsOn: Build

 - deployment: DeployUAT
   displayName: Deploy to UAT
   environment: UAT
   dependsOn: DeployTest

You can see that I needed to add dependsOn to get the to work sequentially: not doing this would trigger all jobs at the same time (and subsequently fail the deploys, since the artifacts where not available).

Missing stages

Looking back, the first clue was that I didn’t get multiple stages in any overview page: Pipeline runs overview with only one stage visible

My confusion came from this screen and not making the connection. The different ‘stages’ of my pipeline where showing here, so why not in the overview page? Job overview showing multiple jobs

Finding a solution

Skipping the confusion part (I assumed I must have done something wrong or Azure DevOps changed something since I last checked), I continued with adding approvals to the environments my ‘stages’ where creating.

Environment approval blocks all jobs

Running the pipeline with an approval on one of the environments, blocked the whole pipeline! Not just the job targeting that specific environment, as I was expecting. Environment approval blocks all jobs Searching the web, I came across other people having sort of the same issue, like for example this uservoice. An almost two year old feature request to prevent this scenario from happening?!? Surely this is not happening in Azure DevOps?

Eventually it was this Stack Overflow answer that finally pushed me in the right direction…

Some more hints: Stage picker when starting a pipeline

I learned about a new feature that lets you pick the the stages to run when starting a pipeline run: Pick stages to run on starting a pipeline manually This leads to this message, not making it that much more clear (oh hindsight): Message: Configuration is only available for multi-stage pipelines.

The fix

This is where I felt stupid, shocked and reinforced the ‘magic incantation’ part of the YAML pipelines… The jobs relate to the same jobs in a classic pipeline and you need to wrap them in stages to have an actual multi-stage pipeline!

stages:

- stage: Build
  jobs:
  - job: Build
    steps:
    - task: SomeTask

- stage: DeployTest
  jobs:
  - deployment: DeployTest
    displayName: Deploy to test
    environment: Test

- stage: DeployUAT
  jobs:
  - deployment: DeployUAT
    displayName: Deploy to UAT
    environment: UAT

Now, the pipeline overview actually shows the correct number of stages:

And the approval works as planned: Approvals only blocking the right stage

So: wondering why an approval on an environment is blocking your whole pipeline? Or wondering why you only see one ‘stage’ indicator in the pipeline runs overview? Know you know how to fix it.

Request:

Found this page with mostly the same searching around I was doing? Please let me know! Finding out these posts help someone else really makes my day. That also makes me feel less stupid 😁.