Azure DevOps Multistage Pipeline Approval Gates

Introduction

As you know we mostly used YAML for build pipelines and Classic UI approach for release pipelines until last month. It was a demand from developer community to add capability to support YAML in release pipelines. I am glad to update you all, Microsoft has recently announced(previously it was in preview mode) the multi-stage pipelines for CI/CD in order to club build, test and deploy related templates/tasks at one place i.e. in single YAML file along with environment and deployment strategy.

In order to use multi-stage pipelines you need to do certain steps i.e. activating multi-stage pipeline feature, and defining your environment(DEV, TEST, ACC and PROD). The environment would help you to incorporate all current features from Classic UI release pipelines like approval gates, invoke azure function, validating build task etc. You can refer hoe to article Converting Classic Azure DevOps Pipelines to YAML

YAML build pipeline enables developer to save pipeline as code, however multi-stage YAML pipelines provides ability to scale your pipeline to support both continuous integration (CI) and continuous deployment (CD). In this post I will explain how multi-stage pipelines works and naming conventions to create environment. Let’s start.

Get Started

Activate multi-stage pipeline support feature

1. Navigate to Azure DevOps
2. Go to User settings and click on Preview features option

3. Select the suitable option for evaluation(for me[Login user name] or Organization) and choose Multi-stage pipelines option ON

 

Create environment

1. Navigate to Pipelines => Environments

2. Click on New environment button and required information. Here we would use naming conventions to create environment as this section is common to all teams in project so expect as many environments 🙂
Lets create two environment i.e. Testing(t) and Production(p)

Naming convention: <project name>-<team name>-<environment>-<resource short name> with all characters in small 🙂
Example: github-githubteam-p-env,  github-githubteam-t-env

Set approval gates for environment

Select an environment which you want to set approval gate before deployment. In my example I will set approval gates for Production

Click on three dots at right corner and click Approval and gates option from menu

Click on + button to add checks and select Approvals. Add the approver and click on Create button

Approver list appear in your list. If you want to add more approver the simply click on row and it will render user interface in editable mode.

Setup multi-stage pipeline

Let’s assume I want to deploy my Azure DevOps Extension to marketplace. In order to deploy my extension to marketplace, I have created two publisher namely {publisher}-test and {publisher}

Now, I have my source code with brand new azure-pipelies.yml file with me(Please refer my previous post to setup your first yaml pipeline using Azure DevOps and Git Repos)

Replace/manage all code of azure-pipelies.yml with below source code where I implemented multi-stage deployment


trigger:
- master

# Link variable group
variables:
- name: Version
  value: 2.0.4
- group: Csharpdocs.AzureDevOps.Extension

# Build number format
name: $(Date:yyyyMMdd)$(Rev:.r)

stages:
  - stage: Build
    displayName: 'Build - CI'
    jobs:
    - job: BuildAndPackage
      displayName: Build & Package Extension
      pool:
        vmImage: 'windows-2019'
      workspace:
        clean: all
      
      steps:
        - template: build-artifact.yml
  
  - stage: TEST
    displayName: 'Testing - CD'
    jobs:
    - deployment: PublishExtension
      displayName: Publish extension to marketplace
      pool:
        vmImage: 'windows-2019'
      environment: github-githubteam-p-env
      strategy:
        runOnce:
          deploy:
            steps:
              - template: publish-extension.yml
      
  - stage: PROD
    displayName: 'Production - CD'
    jobs:
    - deployment: PublishExtension
      displayName: Publish extension to marketplace
      pool:
        vmImage: 'windows-2019'
      environment: github-githubteam-p-env
      strategy:
        runOnce:
          deploy:
            steps:
              - template: publish-extension.yml

In above code snippets, I have three stages namely Build(Build – CI), TEST(Testing – CD) and PROD(Production – CD). TEST and PROD has deployment stage where environment is mentioned which we created at start i.e. github-githubteam-p-env, github-githubteam-t-env. Save the code and it will trigger automated build.

The Build and TEST stages are completed and pipeline is waiting for approval

Click on Review button, it would open Approval window with Resource waiting for approval, Approve/Reject button and Instruction body created at time of setting Approver for environment. Let’s Approve it for now 🙂

It will immediately start production deployment. Pipeline successfully deployed production environment

The improved look and feel at pipelines page displays multi-stage pipeline status as

References

Leave a Reply