How to integrate Maven project using Jenkins

Performance-Tests
04 Dec 2020
Continuous Integration is the most important part of DevOps that is used to integrate various DevOps stages.
Jenkins

Jenkins is an open-source automation tool written in Java with plugins built for Continuous Integration and Continuous Delivery purposes.Jenkins is used to build and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. It also allows you to continuously deliver your software by integrating with a large number of testing and deployment technologies.
With Jenkins, organizations can accelerate the software development process through automation. Jenkins integrates development life-cycle processes of all kinds, including build, document, test, package, stage, deploy, static analysis, and much more.
Jenkins achieves Continuous Integration with the help of plugins. Plugins allow the integration of Various DevOps stages. If you want to integrate a particular tool, you need to install the plugins for that tool. For example Git, Maven 2 project, Amazon EC2, HTML publisher etc.

Advantages of Jenkins include:

  • It is an open-source tool with great community support.
  • It is easy to install.
  • It has 1000+ plugins to ease your work. If a plugin does not exist, you can code it and share it with the community.
  • It is free of cost.
  • It is built with Java and hence, it is portable to all the major platforms.
Maven

Maven is a POM (project object model) basedproject management and build-automation tool written in Java. However, it is compatible with projects written in C#, Python, Ruby. In Maven, the software project is developed using its POM (Project Object Model) which includes information about the project and configuration such as construction directory, source directory, test source directory, dependency, plugins, goals, etc.

Maven primarily intends to provide developers with:

  • A comprehensive, reusable, easily maintainable model for projects.
  • Plugins or tools to interact with and operate with this model.

A few Maven features worth mentioning are:

  • Maven can be used to build any number of projects into predefined output types – jar, war, metadata.
  • Maven can automatically download necessary files from the repository when building a project.
  • Maven can integrate with a user’s source control system such as CVS in order to manage the release of a project. This can be done without any additional configuration.
  • It is easy to port multiple modules of a project into Maven 3 from older versions. Maven 3 also supports all older versions.
  • Maven analyzes the project dependency graph and allows for scheduling modules in parallel. This usually facilitates performance improvements.
  • Maven comes with improved error reporting. It offers a link to the Maven wiki page which contains a detailed full description of every error.
Steps to integrate Maven project in Jenkins

1. Adding Maven plugin in Jenkins Open Jenkins and add the Maven integration plugin from the plugin manager.

load-graph

2. Configure a new Maven job, Set up a job in Maven project.

load-graph

3. Integration with Git repository.
After the job setup we need to connect the Jenkins jobs with source code. To do that we have to connect Jenkins with Git repository by using source code management tab in Jenkins. Add the Git repository URL and add the credentials ofGit repository as shown below.

load-graph

Next step is to set up some Webhooks from the Git repository settings to connect with Jenkins.

load-graph

4. Build trigger scheduling.
Without any manual intervention we can schedule our job at any desired time. For that, there is a tab called Build trigger, there it is possible toschedule the jobs. Here is an example showing the build it will trigger everyday 12.30 am.

load-graph

5. Build with pom.xml file.
If you need to build a Maven project we need to setup the pom.xml file and Build and Goal menu.

load-graph

6. Build the job by choice parameter of xml file.
If we need to build the project based on suites like regression, sanity or smoke we can add those parameter as a choice in order to take the build. Here, the example shows that from the test suite you can trigger a suite to run in a chrome browser.

load-graph