Skip to content
Paritosh edited this page Aug 9, 2018 · 1 revision

Welcome to the continuous-integration wiki!

Goal

  • Standardization to minimize CI related ops.
  • CI system as code + infra that is scale-able
  • CI infra over cloud to use native auto scaling features for provisioning Jenkins slaves
  • Builds running over Docker containers

Process flow - Sequence Diagram

Defining Agent in Groovy based Jenkins Pipeline

agent {
    docker {
        image '<docker-image-url-goes-here>'    // Enter Docker Image URL with Maven installed.
        label 'linux'
        args '--net=host'
    }
}
options {
    timeout(time: 2, unit: 'HOURS')
}

Stages definition in Jenkins pipeline

    stages {
        stage('Checkout') {
            steps {
                readCommit()    // Git commit message is read to check if a feature branch is requesting for adhoc sonar analysis
                mavenCheckoutVerify()   // Checkout Gerrit Project's patch set; pipeline triggered via Jenkins Gerrit Trigger Plugin 
                isSonarDisabled()   // DB is queried to check if Sonar is Enabled for the project or not.
                sonarOnFeatureBranch()  // DB is queried to check if Sonar is Enabled for the project's feature branches or not.
            }
        }
        stage('Test') {
            steps {
                mavenTest() // Runs mvn test command
            }
        }
        stage('Sonar Analysis') {
            when {
                expression { return (!SONAR_DISABLED) && ((ADHOC_SONAR) || (SONAR_ON_FB) || (GERRIT_BRANCH =~ 'release') || (GERRIT_BRANCH == 'integration')) }
            }
            steps {
                mavenSonar()    // Runs Sonar Analysis and JaCoCo Report is uploaded to Sonar Server. Jenkins Sonar-Scanner Plugin is used and Sonar Server is configured for it to work.
            }
        }
        stage('Quality Gate'){
            when {
                expression { return (!SONAR_DISABLED) && ((ADHOC_SONAR) || (SONAR_ON_FB) || (GERRIT_BRANCH =~ 'release') || (GERRIT_BRANCH == 'integration')) }
            }
            steps {
                checkQualityGate()  // Sonar-Scanner Plugin's withSonarQubeEnv ensures that Task-ID for Sonar Analysis is stored and SonarQube Server side WebHooks are added for Jenkins to receive QualityGate Status
            }
        }
    }
    post { 
        always {
            notifyStatus()  // Notify Status to Committer
            updateKafka()   // Push Execution Metadata to Kafka
            unitTestReport()    // Upload Surefire-Reports for Jenkins BlueOcean Plugin to display
        }    
    }