CI & CD – 15 things to consider for Continuous integration and deployment

Continuous integration (CI)

CI is a practice that encourages developers to integrate their code into a delivery system often.So that each piece of code is Built and unit tests are run as soon as possible to detect early bugs, after which Automated test suites are run on.

Continuous Delivery or Continuous Deployment (CD)

Continuous delivery (CD) is the next phase of CI. Where CI deals with build and test part, CD is used to focus on what happens after it. Any commit that passes the automated tests can be considered a valid for Continuous Delivery.

Build is delivered in a steady stream like Pre-Prod environment, further tested for all aspects of functionality, including business logics and Performance.

Continuous Deployment (CD) is continuously being able to move to the production environment. where it previously undergoes an automated functional testing (after CI-CD) executed in full scale giving us the confidence to establish a good build to be pushed into production.

It gives Production readiness of every build, Just one step away from pushing to Production Environment.

                               “CI&CD is a Marathon rather than a Sprint”

Importance to shift:

1 ) Smaller code changes are simpler and have fewer unintended consequences. Fault isolation is simpler and quicker. Developer gets insights where and why it went wrong.

2) Broken builds caught early

3) Testability improves due to smaller, specific changes

4) Early Tests = Early Bugs

5) Stops guess work whether your code’s going to work

6) Reduce Integration Problems

7)Noticing Trends – since integrations occur frequently with a Continuous Integration system, the ability to notice trends in build success or failure, overall quality, and other pertinent information becomes possible

8) Providing near-real-time information on the recent build status and code quality metrics.

9) “ No One-Big day Deployment to Production ” .Release cycles are shorter with targeted releases .

10) Continuously aware of current status of project

11) Discover potential deployment issues

Challenges to Overcome:

1)The Biggest challenge for any Large Organization is adopting it , Communication gap between teams can lead to destability.  Everyone & Every team has to co-ordinate and co-work to achieve this and grow into it.

2) Handling dependency in microservices

3) Increase in Pace of Stable Automation tests. To Test each and everything.

4) Making it Fast , Efficient and Reliable enough to Release into Prod.

CI&CD is a well defined Loop. The challenge is to bring all teams together to form this loop.

Stages of above Representation:

  → Commit

      → Build

         → Test

            → Code Analysis

              → Archive

                → Deploy to QA

                   → Automated Tests

                     → Deploy to Pre-Prod

                       → Performance Tests

                         → Approval

                           → Deploy to Prod

This entire WorkFlow needs to be in Pipeline as code model to have scalability and reliability.

Example Snippet for Pipeline as code :

def st(branch,url,store) {

    branch_wk = "${env.JENKINS_HOME}/workspace/${env.JOB_NAME}/${branch}"

    // Checkout Git code from repo
    stage("GIT-Checkout-$branch")
    {
    checkout([$class: 'GitSCM', branches: [[name: "*/$branch"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: "$branch_wk"]], submoduleCfg: [], userRemoteConfigs: [[url: "$url"]]])
    }
    
    // Code Compile 
    stage ("Compile")
    { 
      withEnv(["JAVA_HOME=${ tool 'jdk_1.8' }", "PATH+MAVEN=${tool 'Maven-3.5.2'}/bin:${env.JAVA_HOME}/bin"])
       { sh """cd "$branch_wk" 
        mvn compile"""  }
    }
    
    // Build and Test
    stage("Build&Test")
    {
       withEnv(["JAVA_HOME=${ tool 'jdk_1.8' }", "PATH+MAVEN=${tool 'Maven-3.5.2'}/bin:${env.JAVA_HOME}/bin"])
       {
        sh """cd "$branch_wk"
        mvn clean install  """ }
    }

   // Sonar Analysis
    stage("Sonar")
    {
        withEnv(["JAVA_HOME=${ tool 'jdk_1.8' }", "PATH+MAVEN=${tool 'Maven-3.5.2'}/bin:${env.JAVA_HOME}/bin"]){
        withSonarQubeEnv('Sonar')
      {
        sh """cd "$branch_wk" 
        mvn sonar:sonar""" }
    }
  }

    // Upload to Artifactory
      stage ("Artifactory") {

      def server = Artifactory.server "artifactor"
      def buildInfo = Artifactory.newBuildInfo()
      buildInfo.env.capture = true
      buildInfo.env.collect()

      def uploadSpec = """{
        "files": [
          {
            "pattern": "**/target/*.jar",
            "target": "$store/"
          }
        ]
      }"""
      server.upload spec: uploadSpec, buildInfo: buildInfo
      buildInfo.retention maxBuilds: 10, maxDays: 7, deleteBuildArtifacts: false
      // Publish build info
      server.publishBuildInfo buildInfo
    }
 }

pipeline 
{
  agent any
  triggers { 
      pollSCM('0 */3 * * *') 
  }
  stages
  {
    stage("Function-Call")
     { steps
      {        st('master','https://github.com/example','libs-release')
      } }
}}

 

Example Pipeline Stage view

                         We Live By – Automate All

Article & Image References:

1) https://dzone.com/articles/what-is-cicd

2) http://searchitoperations.techtarget.com/

By: 
Sarvesh Anand
www.coviam.com


Also published on Medium.

Leave a Reply

Your email address will not be published.