Our road to OSS Blueprints - Suppress CD when pipeline runs within Pull Request


Posted by Willy-Peter Schaub on Wed 21 September 2022

A glimpse at our OSS progress and how we use the same pipeline in and out of pull requests.


Open Sourcing our Application-type CI/CD Blueprints

We are on the home stretch to open source our v2 application-type CI/CD blueprints. In fact, we only have one last optimization story enabler to complete, before we will start setting up an OSS repository in GitHub. Thank you for your patience Said - we are close!


Using the same Application-type CI/CD Blueprints as Pull Request (PR) Validation Build

suppressCD parameter

Why do we want to suppress the continuous delivery (CD) part of our CI/CD blueprint-based pipelines?

Pipeline is triggered:

  • By self-service automation, when the configuration is not yet configured.
  • By development team that is not ready to deploy yet.
  • As a validation build within a pull request, where you only want the continuous integration (CI) to run.

In our *start.yml template we have the optional suppressCD parameter:

extends:
  template: blueprints/__101__/azure-pipeline-__101__-control.yml@CeBlueprints
  parameters:
    portfolioName:   '__TODO_PORTFOLIO__'
    productName:     '__TODO_PRODUCT__'
    publishFolder:   '__TODO_FOLDERNAME__'
    suppressCD:      true # Allow engineering to do an immediate CI/build while CD is being configured
    modeElite:       false

When set to true, this part of the control.yml is not* processed.

- ${{ if and(ne(parameters.suppressCD, true), ne(lower(variables['Build.SourceBranchName']), 'merge')) }}:
  - template: /blueprints/__101__/azure-pipeline-__101__-cd.yml@CeBlueprints

As a result the CD part of the pipeline will not be injected at queue time.

Suppress CD within PR

The optional parameter works well, until you are ready to deploy your solution and you set suppressCD = false. In this case the validation build in a pull request would trigger both the continuous integration (CI) and continuous delivery (CD) pipeline phases.

This explains this code snippet at the end of the *-CI.yml template, which suppresses the CD part if the pipeline was triggered by a pull request ("merge"):

- ${{ if eq(lower(variables['Build.SourceBranchName']), 'merge') }}:
  - script: echo CD part of the pipeline is suppressed for pull request validation builds! 
    displayName: PR Validation CD Suppression Alert

magic

It goes hand-in-hand with the second half of the conditional statement after the suppressCD check, as above. The source branch name will be merge if the build originated as a pull request merge validation build.

A simple, but powerful trick!


Series Bread Crumbs | Part 1, TOC | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7 | Part 8 | Part 9 | Part 10 | Part 11 |