Devops Tools

Jenkins integration with Maven

Maven  is a build automation tool used primarily for Java projects, though can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. Jenkins integration with Maven through plugins aids to automate the complete build.

Maven is a program that automates the creation of executable applications from source code. It incorporates compiling, linking and packaging the code into a usable/ executable form, generation of reports and dependency management.

Jenkins integration with Maven

I. Configure Maven in Jenkins

1. Go to Jenkins Dashboard ->Manage Jenkins ->Manage plugins ->Available ->Maven Integration ->Install

2. Go to Manage Jenkins->Global tool configuration->Maven -> Add Maven_home variable value (i.e. path of the maven file on your system). if manually installing the maven

3. Go to Jenkins Dashboard -> New Item -> Maven Project option will be available

II. Build a Maven project

  1. Go to Jenkins Dashboard -> New Item -> Choose name for the Maven Project (e.g. MyFirstMavenExample)

Creating a new job in Jenkins

2. On Configure Page, set the following:

a). Discard Old builds

Days to keep builds: 1

Max of builds to keep: 5

Configuration page of the Jenkins job

b). JDK (to be used for this project) Java-1.8

c). Build -> adavanced -> enable the following

– Resolve Dependencies during Pom parsing

– Use custom workspace (add path of the folder containing pom.xml)

-Goals & Options = Clean Compile Test

Configuration page of the Jenkins job

3). Apply & Save

4). Go to Project Window and Click ‘Build Now’.

Troubleshoot:

*Error : Compilation error - No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
Probable cause: not able to connect to/find jdk.
Solution:
1.    Go to Jenkins dashboard -> Manage Jenkins -> Configure System -> Global properties -> Add Environment Variable : JAVA_HOME and value
2.    Also check in the system of your windows :
System -> advanced settings -> environment variables
Set the PATH : Append with the folder path of the jdk
If, user variable is pointing towards JRE, then update it to point towards java path.
Please follow and like us: