Search Sreeni's Insights

Filter by content type
crafting October 11, 2018 6 min read

How does a change flow from commit to production in CI/CD? - Part 3

How a change flows from commit to production: the release branch workflow, CI and CD steps, quality gates and how we handle build failures.

Share:

How does a change flow from commit to production in CI/CD? - Part 3

Knowing the phases, roles and environments is one thing, but a team needs to know exactly what happens to a change after a developer pushes it: which checks run, who approves what, and what happens when something fails. Without this clarity, the process becomes a set of tribal rules and every team ends up doing it differently. In the previous article, we discussed the roles and responsibilities and the environments. In this article, we are going to see the end-to-end workflow from a code check-in to the production deployment, the CI and CD steps in detail, and how build failures are handled.

CI/CD Process series:

  1. What is CI/CD and why do we need it?
  2. Who does what in CI/CD? Roles and environments
  3. How does a change flow from commit to production in CI/CD? (this article)
  4. How to implement CI/CD with Azure DevOps?

TL;DR Summary

  • A change starts in a user story/bug branch, goes through a pull request and code review, and is merged into the sprint release branch.
  • CI sets the version, compiles with code style checks, runs unit tests, compares code coverage, scans for vulnerabilities and publishes a versioned build artefact.
  • CD deploys the same build artefact to Dev automatically, and then to QA, UAT and production after the approvals at each gate.
  • After production deployment, the source code is tagged and merged to master, and a smoke test is executed.
  • A build fails for compilation errors, code style errors, test failures, vulnerabilities or a reduction in code coverage, and the failure goes back to the developer.

Workflow

The following diagram details the primary workflow (release branch) in the various phases described in the first article. Workflows for other branches, like user story and hotfix branches, follow the same idea with suitable modifications.

Release branch SDLC workflow across the Code, Build, Test and Release & Deploy phases
Release branch SDLC workflow across the Code, Build, Test and Release & Deploy phases

The flow highlighted in purple is the happy path of a change from a user story branch to production; the grey lines are the loops back to development. Let us walk through the diagram phase by phase.

Code Phase (sprint development)

  1. The developer creates a user story or bug branch.
  2. The developer develops the feature or fix and builds it with Visual Studio along with the ReSharper CLI.
  3. The developer raises a pull request.
  4. The code is reviewed. When there is any code issue, the review is rejected and the change goes back to development. When it is approved, the change is merged to the sprint release branch.

Build Phase

  1. The merge triggers the continuous integration build on the sprint release branch. We will see the CI steps in detail below.
  2. When the build fails, it goes back to the developer. When it succeeds, the binaries are published.

Test Phase

  1. The build is deployed to the Dev environment and the developer does the integration test.
  2. The Tech Lead approves the build number.
  3. The QA Lead gives the pre-deployment approval and the build is deployed to the QA environment.
  4. QA does the functional test along with the automated smoke test. When bugs are found, the work goes back to the Code phase.
  5. The QA Lead gives the post-deployment approval for QA and the pre-deployment approval for UAT, and the build is deployed to the UAT environment.
  6. In UAT, the automated smoke, regression, security and performance tests are executed, QA does the functional regression test and the BA does the UAT.

Release & Deploy Phase

  1. The SDM gives the pre-deployment approval for the build number.
  2. CAB approval is obtained.
  3. The Release Champion deploys the build to the live environment.
  4. The source code is merged to master and tagged.
  5. The QA team does the smoke test on the live environment and signs off.
  6. Once the live environment is stable, the build is deployed to the DR (Disaster Recovery) environment, and the QA team does the smoke test and signs off there as well.

Notice that the build number travels with every approval. This is the “build once, deploy many” goal in action: the same versioned build artefact which passed CI is the one that reaches production.

High Level Workflow

CI

  1. The version number is set in the AssemblyInfo.cs file for .NET Framework projects and in the project files for .NET Core projects.
  2. The source code is compiled. As part of the compilation, ReSharper is triggered to check the code style.
  3. The unit tests are executed.
  4. The unit test code coverage is analysed, published and compared with the previous build.
  5. Checkmarx does a vulnerability assessment.
  6. A standalone version file is created (optional for .NET projects).
  7. The build artefact is generated and published.

CD

  1. The build is pushed to the Dev (integration) environment automatically.
  2. Deployment to the QA environment is triggered.
  3. The test cases are executed in QA.
  4. Deployment to the UAT environment is triggered.
  5. The regression, automated and performance test cases, etc. are executed.
  6. BA/SDM testing is done as required.
  7. CAB approval is obtained.
  8. Deployment to the production environment is triggered.
  9. A tag is generated and the code is merged to the master branch.
  10. A smoke test is executed in the production environment.

Quality gates at a glance

The following table summarizes the automated checks and the manual approvals in the workflow,

StageAutomated checksManual approvals
CodeReSharper code style (local)Code review on the pull request
Build (CI)Compilation, ReSharper code style, unit tests, code coverage comparison, Checkmarx vulnerability scan-
DevBuild Verification Tests (when available)Developer integration test, Tech Lead approval
QAAutomated smoke testsQA Lead pre- and post-deployment approval, QA functional test
UATAutomated smoke, regression, security and performance testsQA Lead pre-deployment approval, QA regression test, BA UAT
ProductionSmoke testSDM pre-deployment approval, CAB approval, QA sign-off

The more of the right-hand column we can move to the middle column, the closer we get to true Continuous Delivery.

Build Failures

A build can fail in the CI process for the following reasons,

  • Code compilation errors
  • Compilation errors triggered by ReSharper
  • Unit test (or other test) failures
  • Vulnerabilities in code found by Checkmarx
  • Reduction in code coverage between successive builds

A build failure triggers an email with an appropriate description. For more details, the logs of the build can be viewed in the Logs section of the failed build, as seen in the following screenshot.

Failed build in Azure DevOps with the failing step in the Logs section
Failed build in Azure DevOps with the failing step in the Logs section

Must Do: Fix a broken build before you push any new change. A build that stays red stops everybody else from integrating, and that defeats the purpose of CI.

Wrap up

In this article, we have looked at the end-to-end release branch workflow, the CI and CD steps, the quality gates at each stage and how build failures are handled. I really appreciate that you took the time to read this article. In the next article, I will walk you through how to implement this workflow with Azure DevOps, the tools and pipeline tasks we use, the challenges we faced and our recommendations.

Related Posts