Day 25: 90DaysOfChallenge

Day 25: 90DaysOfChallenge

Complete Jenkins CI/CD Project - Continued with Documentation

Jenkins is an open-source automation tool for Continuous Integration (CI) and Continuous Deployment (CD). It is a server-based system that runs in servlet containers like Apache Tomcat. Jenkins is one of the most used DevOps tools used along with other cloud-native tools and allows developers to build, test and deploy software seamlessly.

Here's the documentation of the process from cloning the repository to adding webhooks and Deployment.

Pre-requisite

  • EC2 instance

  • Docker and docker-compose installed

  • Jenkins installed

  • GitHub Account

Steps-

  1. Login to AWS account and create an EC2 instance.

  2. Connect the EC2 instance.

  3. Install docker in EC2 instance.

sudo apt-get install docker.io
  1. Install Java as it is required for Jenkins.

     sudo apt update
     sudo apt install fontconfig openjdk-17-jre
     java -version
     openjdk version "17.0.8" 2023-07-18
     OpenJDK Runtime Environment (build 17.0.8+7-Debian-1deb12u1)
     OpenJDK 64-Bit Server VM (build 17.0.8+7-Debian-1deb12u1, mixed mode, sharing)
    
  2. Install Jenkins.

     sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
       https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
     echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
       https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
       /etc/apt/sources.list.d/jenkins.list > /dev/null
     sudo apt-get update
     sudo apt-get install jenkins
    
  3. Add the EC2 user to docker group to prevent the user from getting "Permission denied" error.

     sudo usermod -aG docker $USER
    
  4. Add the Jenkins to Docker group so that docker can be accessed from Jenkins.

     sudo usermod -aG docker jenkins
    
  5. Add the port 8080 to inbound rules as Jenkins server works on port 8080.

  6. Open the Jenkins url and if not logged in, sign up for Jenkins. Install the required plugins and proceed.

  7. Create a freestyle project in Jenkins via GitHub by selecting GitHub Project and GIT under SCM and providing the repository url.

  8. Also, select "GitHub hook trigger for GITScm polling" under Build Triggers section. This initiates the build trigger as soon as any update is made on the code.

  9. Save the Configuration.

  10. Now go to GitHub and open the repository.

  11. Open the Settings of that repository and click on WebHook.

  12. Now click "Add WebHook" and provide the Jenkins url followed by "/github-webhook/" and save.

  13. Once webhook is added, make any changes in the code and commit those changes.

  14. Go back to Jenkins under the recently created project and check the build trigger.

  15. Build would have been initiated automatically as it listens to the GitHub and would start as soon as the changes were committed.

  16. Visit the address of EC2 instance with the exposed port of the application to view the running application.

    The complete CI/CD pipeline has been created and is working.

    Thanks for reading!

~Happy Learning!