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 🤔.
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).
Looking back, the first clue was that I didn’t get multiple stages in any overview page:
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?
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.
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.
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…
I learned about a new feature that lets you pick the the stages to run when starting a pipeline run:
This leads to this message, not making it that much more clear (oh hindsight):
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:
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.
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 😁.