DevOps CICD Pipeline Setup Through { Jenkins | Nexus | Sonarqube | Tomcat | Maven }

Rahul .
9 min readNov 4, 2022

--

So as a part of this setup, we are going to use several tools first, our project is available on GitHub where the project source code will be available. So will take a project from GitHub and deploy it using different stages with the help of the CICD structure.

In order to build and deploy that application we are using Jenkins. In Jenkins, we are using the CICD pipeline concept. So this Jenkins software is going to clone the repository from GitHub and will communicate with Maven.

Maven: It is a build tool used to perform the build process for Java applications.

Now Jenkins will clone the repository from the github and maven will compile and package our java application. After the build process is completed Jenkins should be able to communicate with the Sonarqube.

SonarQube: To perform code review Sonarqube plays the code quality checking software in the pipeline.

After performing the code review of our application we want to build an artifact into the Nexus Repository.

Nexus: Nexus is the repository where all the artifacts are placed.

After uploading the artifact into the nexus repository we want to deploy the application war file into the apache tomcat server.

Apache tomcat server: is a container that is used to run our web applications.

We will use the Tomcat server for running our Java application. My Jenkins is responsible for communicating with all the tools to automate the application build and deployment process. In order to perform all these steps we are going to create a pipeline in Jenkins.

After that, we will create AWS Linux Machine, you can use any machine in your comfort zone.

We would be creating 4 servers as described below:

For this project, we will be using Linux Machine for the installation of the tomcat server.

For installation of Tomcat Server:

For installation of SonarQube :

For quick installation of Nexus :

For Installation of Jenkins:

So we will breakdown the project into five phases which are as followed

Stage 1: Clone Repository

Stage 2: Maven Build

Stage 3: Code Review

Stage 4: Upload Artifacts

Stage 5: Deploy the App

First Stage: Clone the Repository

So in this pipeline’s first stage, we’re going to clone the git repository in my Github account.

You can find the details down below :

Now let’s start configuring the Jenkins :

Firstly we need to set up maven as a global tool configuration in the Jenkins dashboard.

Now Let’s Start building the pipeline:

Now Apply and Save.

Just Run the pipeline and see whether the first stage is processing or not. So Click Build Now:

So we have completed our first stage. Now we proceed to the second stage which is Maven Build.

Second Stage: Maven Build

Now Apply and Save.

Just Run the pipeline and see whether the second stage is processing or not. So Click Build Now.

So as the second stage is completed which is Maven build and now we will proceed to the third stage which is Code Review.

Stage 3: Code Review

This stage will be entirely covered by Sonarqube for the code review and analysis. For this, we need to integrate Sonarqube with Jenkins Server. In order to integrate Sonarcube with Jenkins we have to install a plugin named as SonarQube Scanner. Select this plugin and install it without restarting.

Now Login into SonarQube then move into Administrator >> Account >> Security >> Generate Token

Here Generate a Token according to your feasible name and copy the token to the Jenkins panel.

Add to your new Credentials of SonarQube into Jenkins by moving to the path Dashboard >> Credentials >> System >> Global Credentials (unrestricted). Add your Secret Key over here.

In Jenkins Dashboard move into Manage Jenkins >> Configure System >> SonarQube Servers >> Add SonarQube.

Click on Apply and Save. With this, you have configured Jenkins with SonarQube. Now, let us move into the pipeline and add a stage for the SonarQube Stage.

Click on Apply and Save it for further procedures.

Now Run the Build Now and see whether the pipeline is fully functional or not. This is the time we have three stages in the pipeline.

If the Build is in the success stage you will find that your maven web app is in the SonarQube.

Now let’s build our fourth stage.

Stage 4: Upload the Artifacts

For this stage, we have to configure the Nexus Artifact Repository System into Jenkins.

So move into the Jenkins Dashboard >> Manage Jenkins >> Plugin Manger >> Available

Install the Nexus Artifact Uploader

Let’s add the fourth stage in the Pipeline for the fourth stage.

Use Pipeline Syntax to generate the stage for the Script.

Provide the details of the Nexus Repository as per your configuration in Jenkins pipeline syntax.

Create a Repository in Sonatype Nexus and pass the user credentials into the Jenkins Pipeline Details.

Now add the details to the Artifact Tabs.

Now pass the Script into the Nexus stage.

Click on Apply and Save.

Now, let's run the Build now and check whether the pipeline Upload the Artifacts is functioning or not. At this time we have 4 different stages to run.

Now Check Your Nexus Repository, you will find the Artifacts uploaded into the directory system.

Now we can see that the 4 stages have been completed successfully. Now we will proceed to our final stage for Deploying the app.

Stage 5: Deploy the App

For deployment, we need an ssh-agent. For this move to Dashboard >> Manage Jenkins >>Plugins Manager >> Available

Here install search for the SSH Agent. Install it without restarting.

Now let’s add a stage for the deployment. Use pipeline syntax to create the script.

Now add credentials for the Tomcat Server.

Provide the private key .pem file for the tomcat server and click on ADD. Now Generate the Pipeline Syntax for the Stage.

Now we need to add the Fifth stage to the script for the deployment of our web app.

Add the stage.

Click on Apply and Save and Run the Build Now.

As your build is initiated successfully you can now check the tomcat server for the running web application.

So this is the complete CICD pipeline.

Credits: AshokIT

--

--

Rahul .

I’m a Cloud enthusiast and DevOps student with over a year of experience in Database & Channels Administration in banking sectors .