How to setup Jenkins for a Maven project

29 / Jul / 2015 by Dipti 3 comments

This blog post shows how to configure maven project in Jenkins. Follow these steps for Jenkins Maven project configuration:

Step 1 – Starting Jenkins

a) Download Jenkins Zip file and extract it(i have downloaded for windows as i am setting it up on windows7)

b) In cmd go to the path you have extracted Jenkins (eg.C:\Program Files (x86)\Jenkins)

jenkins maven configuration

c) To start the Jenkins, run the command jenkins.exe start
-To restart the Jenkins: Jenkins.exe  restart
-To stop the Jenkins: Jenkins.exe  stop

d) By default, it will open up on 8080 port as  localhost:8080 (make sure nothing else is running on port 8080)

jenkins maven build screen

Step 2 – Creating and configuring user on Jenkins

a) To create a user go to Manage Jenkins->Manage Users->Create User->Provide the required information

how to configure maven project in jenkins

b) Go to Manage Jenkins->Configure Global Security
-Check Enable security
-In Security Realm, select Jenkins own user database and check Allow users to sign up
-In authorization, there are multiple options select as per requirement
-Save once done

jenkins maven project configuration

Step 3 – Configuring System

a) Go to Manage Jenkins->Configure System

b) Configure JDK
-Give the JDK name
-JAVA_HOME : C:\Program Files\Java\jdk1.7.0_45

c) Maven configuration
-Give a maven name
-MAVEN_HOME : C:\apache-maven-3.2.5\apache-maven-3.2.5-bin\apache-maven-3.2.5

d) Global Maven_OPTS
–Xmx512m
–XX:MaxPermSize=128m

e) Save once done

jenkins maven project configuration

Step 4 – Adding Plugins

a) Go to Manage Jenkins->Add Plugins

b) Install the plugins which are required, Eg. GIT client plugin: which Shared library plugin for other Git related Jenkins plugins,  GIT plugin: This plugin integrates GIT with Jenkins etc.

Step 5 – Creating jobs

a) Go to New Items->Give a project name in “Item name” field->select Maven project->click OK

b) Now configure the job
-Provide the description
-In Source Code Management, there are options for CVS project, Git etc,  select the one which is required

jenkins maven plugin creating jobs

– In Build Triggers, there are multiple options like “Build when a change is pushed to GitHub”, “Poll SCM”, “Build whenever a SNAPSHOT dependency is built” etc, select the required one
– Give the path of your pom.xml file in Build Root POM
– Give “Goals and options“  take a use case where the requirement is to install the code then give ”clean install”

jenkins maven integration with jobs confguration

c) Configure the job as in the screenshot and don’t forget to save

d) In the same way, create another job(4503_deploy)

e) Suppose the requirement is creating two jobs, one(4502_deploy) for deploying the code on author instance 4502 and if it’s built is successful than it should run its downstream job(4503_deploy) for deploying code on publishing instance.

f) Now configure the job “4502_deploy”, In Post Steps select “Run only if build succeeds”

g) In Post Build Action, add post build action and give the job name(4503_deploy) in “Projects to build

configure Jenkins Maven Job

Step 6 – Build the jobs

Now build the job “4502_deploy”, on successful completion “4503_deploy” will trigger automatically and hopefully, jobs will be successful!!!

Following these steps above, you will be able to configure your Maven project over Jenkins.

FOUND THIS USEFUL? SHARE IT

comments (3)

Leave a comment -