Efficiently Deliver Your Maven Project with End-to-End CI/CD Pipeline

Utsav Desai
7 min readApr 12, 2023

--

Requirement: You must have Jenkins and Docker files in your GitHub repository.

Jenkins configuration Setup on EC2

here’s a step-by-step guide on how to set up Jenkins on an EC2 instance:

1. Launch an EC2 instance: Go to the AWS Console, select EC2, and launch a new instance. Choose an Amazon Machine Image (AMI) that has the operating system you prefer. For example, you can choose Ubuntu or Amazon Linux.

  • Click Launch instances and then create your instance.
  • Give your instance a name and select Ubuntu as the operating system.
  • Create a new key pair, then click the Launch instance button.
  • Make sure your instance is running.

2. Configure Security Group: Make sure you create a security group for the EC2 instance that allows access to port 22 (SSH) and port 8080 (Jenkins UI).

3. Connect to the instance: Use SSH to connect to the EC2 instance. You can use the key pair you created while launching the instance.

4. Install Jenkins: To install Jenkins on Ubuntu, use the following commands:

sudo apt update
sudo apt install docker.io
sudo docker run -p 8080:8080 -p 50000:50000 -d -v jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock learnwithparth/my-jenkins:1.0

5. Open Jenkins UI: Open a web browser and go to http://[EC2_Instance_IP]:8080. You should see the Jenkins login page.

  • To find the Administrator password, use the following instructions.
  • Enter the Administrator password and click Continue.
  • Click the Save and Finish Button.
  • Click Start using Jenkins Button.
  • Once your Jenkins setup is complete, you can begin working with Jenkins and creating jobs.

Continuous Integration Pipeline

Our purpose here is to do this work.

  • Clone the provided sample GitHub repository to the Jenkins server- (Unique IP).
  • Develop a pipeline in Jenkins to build the source code of the repository.
  • Configure the pipeline to run tests if needed/provided in the repo
  • Create a Docker image of the application after successful building and testing.
  • Push the Docker image to the Public Docker Hub repository.

We are taking advantage of the Pipeline project. If we want this practical, we need to create a Jenkins file in our project. This Jenkins file covers all of our tasks, such as cloning Github code, creating and testing Projects, creating and testing Docker images, and finally publishing the Docker image to the Public Docker Hub repository.

1. Firstly, we require that your project be available on GitHub.

2. Jenkins requires some configuration.

  • Select Manage Jenkins.
  • Select Global Tool Configuration.
  • Add your Maven, check that the Maven installation name matches the name in your Jenkins file, and then click the Save button.
  • Select Manage Plugins.
  • Install any plugins needed for Project. Choose plugins, then install without restarting.
  • Select Manage Credentials.
  • Select System.
  • Select Global credentials (unrestricted).
  • Select Add Credentials Button.
  • Enter the credential information from your Jenkins file.
  • When the creation is complete, your page should look like this.

3. Create Jenkins Job.

  • Select Create a Job.
  • Enter the name of your pipeline, then click the OK button.
  • Select Pipeline script from SCM.
  • Select SCM as a Git.
  • Enter the Project GitHub URL.
  • Select Appropriate Branch, then click the Save button.
  • By clicking Build Now, you may run your Jenkins job.
  • Our Build is successfully completed.
  • Our image is successfully Pushed in the docker hub.

4. This is not an appropriate approach to see a build job before you see it. We need some mechanism so that when the developer pushes the code to GitHub, our Jenkins job is automatically build.

  • WebHook is used to fill this need. You may add a WebHook Url to a Github Project by going to Project Settings and then clicking Webhooks.
  • Fill in the WebHook URL.
  • Select the GitHub hook trigger for GITScm Polling.
  • Our build number before pushing code is 1.
  • Github code has been pushed.
  • After pushing work to github, the pipeline is automated.
  • Check out DokcerHub as well. Is our new Docker image available?

5. Determine whether the project is accessible via any of our Docker images.

  • Create a new instance with Congifuation and run this command.
sudo docker run -p 8080:8080 -d utsavdesai26/spring-boot:null-2
  • Add a Security Group to allow access to the 8080 port.
  • http://[EC2_Instance_IP]:8080 can be used to access the project.

The following tutorial will show you how a real-time project works in the DevOps field.

What’s Next?

We are going to study some other DevOps practices.

“Success is a lousy teacher. It seduces smart people into thinking they can’t lose.”

--

--

Utsav Desai
Utsav Desai

Written by Utsav Desai

Utsav Desai is a technology enthusiast with an interest in DevOps, App Development, and Web Development.

No responses yet