Akansha
Introduction to Integration of DEVOPS tools
9 min readOct 29, 2020

--

Now-a-days most of the companies are adopting DEVOPS culture. The key principle of DEVOPS is ‘automate everything’, i.e., it emphasizes on automating everything to make software development process faster and efficient. Continuous Integration and Continuous Delivery (CI/CD) pipelines are created to automate various tasks. Here we are going to automate various tasks by integrating some DEVOPS tools: Jenkins, GitHub for source code management, maven for build automation, SonarQube for code analysis, nexus for artifact management.

Let’s start by installing Jenkins:

Download Jenkins.war file

Start Jenkins through cmd with command “java -jar Jenkins.war” , can also mention port with –- httpPort=port_no , the default port is 8080

Open localhost:8081 on browser

Enter Admin password present at the above given location in user’s directory

We will execute a simple first job in Jenkins to become familiar:

Creating a freestyle project to run date command on shell

Click on New Item, select freestyle project

In Build section, choose execute shell and enter ‘date’ command, now click on ‘Build Now’, when we build the project, ‘date’ command will be executed in shell and current date will be printed as output.

We have created and executed a simple job in Jenkins.

Now that we are familiar with Jenkins, let’s Integration maven, Jenkins and GitHub

Create a simple Maven Project :

Commit and push the maven project to GitHub:

In Jenkins, click on Global Tool Configuration and configure Git executable file path (copy the location of git.exe in your local machine and paste it here)

In Global Tool Configuration set the maven installation path (copy the location from your local machine and paste it here)

In Jenkins, click on New Item, select maven project, copy the URL of GitHub repository we just created and fill it in ‘Repository URL’

In build triggers select ‘Poll SCM’ and fill five starts with space, now whenever a new commit gets generated in the GitHub repository, the change shall be pulled and build shall be triggered automatically.

When build process finishes, the SUCCESS status shows that it was build successfully.

Now whenever we add changes to this maven project and push on GitHub, those changes will be pulled by Jenkins and build will get triggered automatically. This way, watching the build status, code build failures can be found easily.

We have Integrated maven, Jenkins and GitHub, now we will first do static code analysis using SonarQube and then integrate SonarQube with Jenkins.

Download sonarqube:

Start SonarQube in cmd:

Default port for sonarqube is 9000

Open http://localhost:9000 on browser

Login to sonarqube admin user, default password for admin user is ‘admin’

In the previously created maven project, write a simple java code:

Run command “mvn clean install sonar:sonar -Dsonar.host.url=http://my.server:9000/sonar -Dsonar.analysis.mode=publish”

After build Success we can see the detailed code analysis on SonarQube:

We have done static code analysis using SonarQube, now lets integrate Jenkins with SonarQube.

In previous steps we added a java code in maven project, now commit and push these changes to GitHub

Install plugins for SonarQube on Jenkins:

SonarQube configuration on Jenkins:

Edit the maven project, we created in Jenkins and add the command shown below in Goals and options

Build the project and see console output. If build finishes successfully then open SonarQube

Code analysis is automatically triggered, by Jenkins, in SonarQube:

Click on issues to check the issues in analysed code

SonarQube is a very powerful tool for code analysis, using it we can find out the bugs in our code and can make the code more efficient.

Till now, we have integrated Jenkins, GitHub, maven and SonarQube, now we will create a simple pipeline in Jenkins using Jenkinsfile.

For this, we will first create a repository on GitHub and add Jenkinsfile, this file contains the pipeline configuration.

Inside Jenkinsfile:

Now we need to create a new Jenkins project, select pipeline project. In project configuration, select Git in SCM, copy the URL of created GitHub repository and paste it here in ‘Repository URL’. In script path we can see Jenkinsfile, that means this file will be searched in GitHub repository and if found, it will be used to create pipeline. Now save the project and click on Build Now

Pipeline is created and is visible in the project dashboard in Jenkins

Pipeline creation is very important and useful task for CI/CD, by creating pipelines, all the major tasks can be automated. To make pipelines more flexible and interactive, Blue Ocean plugin is used in Jenkins. Now we will create a simple pipeline using Blue Ocean plugin.

Install Blue Ocean plugin in Jenkins:

After installing plugin, an option to open blue ocean is available

Click on Open Blue Ocean

To use GitHub repository, having Jenkinsfile, to create pipeline, we need to complete GitHub authorization and the repository can be integrated.

Click on GitHub, click on create access token, you will be redirected to GitHub, after authentication access token will be provided on GitHub. Copy the access token and paste it here, choose organization and repository (having Jenkinsfile)

After finishing GitHub authorization and repository integration, click on Create Pipeline button, the pipeline will be created, it might take some minutes to complete pipeline creation. If it fails, check the Jenkins file and do necessary changes. When pipeline is created successfully, a green check will be shown in pipeline status.

Pipeline is created, click on it to view details of each phase, we can see the steps performed and messages printed.

Till now, we have created three projects in Jenkins: first- simple freestyle job, second- maven project and third- pipeline project.

Now finally we will upload artifact to nexus repository. This will be done automatically by Jenkins after some configuration.

download nexus:

After the download finishes, we can see two directories, as shown above.

Open cmd, navigate to the first directory’s bin and run nexus as shown below:

Default port for nexus is 8081, it can be changed in nexus-default file:

Open http://localhost:8083 on browser:

Login using the initial admin password, present at given location:

Click on settings icon, click on Repositories:

Create new repository as shown below:

In the maven project, we created previously, add nexus server username and password in the settings.xml file.

In the pom.xml file add distribution management tag as shown in the screenshot below, provide the correct URL of nexus repository which we created in previous steps. Push the changes on GitHub.

In Jenkins, install plugin for nexus:

In global tool configuration of Jenkins, configure jdk path (copy the location of jdk installation in local machine and paste it here)

Configure nexus repository manager server in Jenkins, write the URL of nexus server running on your machine and add valid credentials.

Create and configure maven project on Jenkins

In goals and options write ‘deploy’ to create artifact of the project, on build trigger, and upload it to nexus server.

After finishing the configuration, build the project

After build completion open the nexus server, click on browse, select the repository created in previous steps. The artifact is uploaded on nexus server.

The snapshot of artifact can be seen in repository, as per our repository configuration.

In this blog, we made some simple projects to integrate some DEVOPS tools and automate various tasks.

--

--