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-
Login to AWS account and create an EC2 instance.
Connect the EC2 instance.
Install docker in EC2 instance.
sudo apt-get install docker.io
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)
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
Add the EC2 user to docker group to prevent the user from getting "Permission denied" error.
sudo usermod -aG docker $USER
Add the Jenkins to Docker group so that docker can be accessed from Jenkins.
sudo usermod -aG docker jenkins
Add the port 8080 to inbound rules as Jenkins server works on port 8080.
Open the Jenkins url and if not logged in, sign up for Jenkins. Install the required plugins and proceed.
Create a freestyle project in Jenkins via GitHub by selecting GitHub Project and GIT under SCM and providing the repository url.
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.
Save the Configuration.
Now go to GitHub and open the repository.
Open the Settings of that repository and click on WebHook.
Now click "Add WebHook" and provide the Jenkins url followed by "/github-webhook/" and save.
Once webhook is added, make any changes in the code and commit those changes.
Go back to Jenkins under the recently created project and check the build trigger.
Build would have been initiated automatically as it listens to the GitHub and would start as soon as the changes were committed.
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!