Deploy Java application with Complete CI/CD pipeline Jenkins

Prashant
5 min readOct 12, 2022

--

In this article, we will discuss how to create a complete CI/CD pipeline using jenkins to deploy a java application. So let’s start. But before jumping to practical what is jenkins and ci/cd.

What is Jenkins?

To show our application to the client, there is multiple steps happen like dev writes code, pushes the code in SCM(Github), then deploys the app locally, then testing the team test app then after giving a report(approval) to admins then finally application goes to production environment(Public) world. In today’s world how faster you do things is completely impacted your business application. To do these multiple steps faster we have one tool Jenkins to do things faster, easily manageable, and reliable.

What is Pipeline?

Above we have multiple steps, in jenkins world steps are also called jobs, to do multiple steps, we have to create separate jobs and we have to do step by step, so we connect multiple jobs and run jobs one by one this is known as pipeline, we connect and run multiple jobs to create a pipeline.

What is CI?

First, devloper writes the code then push into SCM, then the app deploys in a developer environment, then the testing team test the application through some test cases/unit/integration testing, etc. if the application has some bug or not working properly, then the again tell to dev to fix the issue then push again, this process follows till application work 100% correct, this is known as continuous integration.

What is CD?

After the testing team tests the application ci part is done. After this process testing team has to create and give one report also known as approval to the application admin then they check and push the application to the production environment, You can give this approval manually by asking by email, prompt, etc, or You can do this approval automatic without asking but do only if you have confident about your testing guys, If you do manual this process known as Continuous Delivery if you do this automatic then this process known as Continuous Deployment.

Now let's start the practical part, you have to install some software.

  • In my case, I am using Redhat 8 and the jenkins version and the java version(Must install in the system), java17 because this version is compatible with jenkins latest version.
  • Install git, maven
  • Start jenkins 1st
  • Install Docker

Now open the browser and type http://system_ip:8080, Because jenkins works on 8080 port no by default you can change it also.

Step 1:- Create a new Job, go to a new item, give name select pipeline as code, because we are going to write code

Now write code, save.

Now click on build now to start the pipeline.

First, we see about Continuous delivery(Asking for approval).

If we do continuous deployment then they deploy the app directly to production without asking for approval.

Now check whether our application is successfully deployed or not. We deployed this application in a docker environment.

First Dev writes code and pushes in SCM and checks app is deployed in their environment also called dev environment.

Then testing team deploy and check app in their env also known as the testing environment.

Finally after testing is complete then your app goes to the production environment.

This application is inside the container which is exposed so we can access it publicly. All commands and steps code are written in jenkinsfile.

But in the script, we push image on the docker hub also, So you need to give the password also inside the script or you can create a variable and give a variable inside the script.

How Come to jenkins homepage, Go to manage jenkins :-

Go to Manage Credentials :-

Go to System:-

Add Credentials :-

Select kind and give some info.

That’s how you can create variables.

To get the Github code:- Click Here

Thanks for reading this article I hope this article might helpful to you.

--

--

Prashant

Experienced, Passionate Software Development Engineer proficient in backend, frontend, Cloud Computing, and DevOps with 1+ years of hands-on expertise.