Pull down to refresh

Simple CI/CD pipeline Integrating Jenkins with Maven and GitHub to Build a job on a Tomcat server.

date
Apr 26, 2024
slug
simple-ci-cd-devops-project
author
status
Public
tags
DevOps
Jenkins
Projects
Maven
Tomcat
Github
summary
A company would use a CI/CD pipeline integrated with Jenkins, Maven, GitHub, and Apache Tomcat to streamline and automate the software development and deployment processes.
type
Post
thumbnail
devopsinterview-banner.png
category
📢 DevOps Blogs
updatedAt
Apr 25, 2024 05:58 PM

Overview:

A company would use a CI/CD pipeline integrated with Jenkins, Maven, GitHub, and Apache Tomcat to streamline and automate the software development and deployment processes. Jenkins serves as the automation server, orchestrating the pipeline, while Maven manages project dependencies and builds. GitHub acts as a version control system, enabling collaboration, and Apache Tomcat facilitates the smooth deployment of applications, ensuring efficient and consistent delivery of software updates. This integrated toolchain enhances development speed, ensures code quality, and simplifies the continuous delivery of software applications.

Objectives:

  • Setup Jenkins
  • Setup & configure Maven and Git
  • Setup Tomcat Server
  • Integrating GitHub, Maven, Tomcat Server with Jenkins
  • Create a CI and CD job
  • Test the deployment
Prerequisite:
  • AWS account(free-tier)
  • Java-open-jdk11
  • PowerShell
  • GitHub account
notion image

♾️Step 1: Set up Jenkins

1. Install Jenkins on an Amazon Linux 2 AMI EC2 instance using the official guide.
sudo wget -O /etc/yum.repos.d/jenkins.repo \https://pkg.jenkins.io/redhat-stable/jenkins.repo sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key sudo yum upgrade sudo yum install fontconfig java-17-openjdk sudo yum install jenkins
2. Name the EC2 instance, choose Amazon Linux 2 AMI, and configure security groups to expose port 8080.
notion image
notion image
3. Connect to the instance via SSH and install Jenkins using the Red Hat package.
notion image
notion image
notion image
4. Resolve Java compatibility by installing EPEL and Java 11.
sudo amazon-linux-extras install epel sudo amazon-linux-extras install java-openjdk11
notion image
notion image
notion image
notion image
5. Start Jenkins, obtain the public IPv4 address, and access Jenkins in the browser.
notion image
notion image
notion image
notion image

♾️Step 2: Open Jenkins, set up an admin account, and install plugins.

1. Unlock Jenkins using the initialAdminPassword.
notion image
2. Close plugin customization and start using Jenkins.
notion image
3. Create a Freestyle project named “HelloWorldJob” with a simple shell script.
notion image
notion image
4. Build the job and check console output for success.
notion image
notion image

🥇Congratulation you have successfully created your Jenkins server and executed your first job!!!

♾️Step 3: Install and configure Maven and Git

1. Install Git on the Jenkins machine using yum install git.
notion image
2. Configure Git plugin in Jenkins.
notion image
notion image

🥈Congratulation you have successfully installed and configured Git on your Jenkins machine!!!

3. Install Maven on the Jenkins machine from a binary tar.gz file.
notion image
 
notion image
 
4. Configure Maven in Jenkins under the Tools tab.
notion image
 

♾️Step 4: Setup Tomcat Server

1. Download and install Apache Tomcat 10 on an EC2 server.
notion image
 
2. Configure security groups to allow traffic on port 8080.
notion image
 
3. Install Java on the server using amazon-linux-extras.
notion image
 
4. Install and configure Tomcat by downloading and extracting the files.
notion image
 
notion image
 
5. Start Tomcat and access it through the browser.
notion image
notion image
 
6. Edit context.xml files to allow external access to the Manager app.
notion image
 
7. Configure users and roles in tomcat-users.xml.
notion image
8. Restart Tomcat and log in to the Manager App.
 
notion image
notion image
notion image
 

♾️Step 5: Integrate GitHub, Maven, Tomcat Server with Jenkins

1. Download the Deploy to Containers plugin in Jenkins.
notion image
 
2. Configure global credentials for Tomcat server in Jenkins.
notion image
 
3. Create a new Jenkins job named “BuildAndDeployJob” as a Maven project.
notion image
 
4. Configure the job to connect to the GitHub repository.
notion image
 
5. Set build goals, options, and post-build actions to deploy artifacts to the Tomcat server.
 
notion image
notion image
6. Build the job and observe the process.
notion image
 

♾️Step 6: Test the Deployment

1. Clone the hello-world repo to a local machine.
notion image
 
2. Make modifications to the code and commit changes to trigger CI/CD jobs.
notion image
 
3. Verify successful deployment on the Tomcat server.
notion image

🥉Congratulation you have now installed Maven and built your very first project from GitHub on a Tomcat server using Jenkins as your CI/CD pipeline!!!

Conclusion!

By following these steps, you should have a robust CI/CD pipeline set up with GitHub, Jenkins, Maven, and Tomcat, facilitating efficient and automated application development and deployment. Hopefully this tutorial was fun and informative. Thank you for following along, happy coding!
 
Thank you for reading my blog …:)
© Copyrights: ProDevOpsGuy

Support 🫶

  • Help spread the word about ProDevOpsGuy by sharing it on social media and recommending it to your friends. 🗣️

Thank you for reading this long article.
Feedback on typos and content is always welcome.

#DevOps#Github#Jenkins#Maven#Projects#Tomcat