Continuous Integration

Section 2: Continuous Integration (CI)

Lesson 1: Continuous Integration Concepts

Continuous Integration (CI) is a crucial DevOps practice that involves frequently integrating code changes into a shared repository. This ensures early detection of integration issues and allows for automated builds and tests.

jenkinsfile


// Jenkinsfile for Continuous Integration


pipeline {

    agent any

    

    stages {

        stage('Checkout') {

            steps {

                // Checkout the code from the version control system

                git 'https://github.com/your-repo.git'

            }

        }

        

        stage('Build') {

            steps {

                // Build the project using build tools (e.g., Maven, Gradle)

                sh 'mvn clean install'

            }

        }

    }

}


Lesson 2: Automated Testing

Automated testing is an integral part of the CI pipeline, ensuring that code changes do not introduce new defects. Various types of automated tests, such as unit tests and integration tests, contribute to a robust testing strategy.

java

// Sample JUnit Test for Java


import org.junit.Test;

import static org.junit.Assert.*;


public class MyUnitTest {

    

    @Test

    public void testAddition() {

        int result = MathUtils.add(2, 3);

        assertEquals(5, result);

    }

}

In this example, the automated test checks if the add method of MathUtils correctly adds two numbers.

This concludes Section 2 on Continuous Integration Concepts and Automated Testing. In the next section, we'll explore Continuous Delivery and Continuous Deployment.