April 9, 2020
Estimated Post Reading Time ~ 2 mins

How to setup Jenkins for a Maven project

This blog post shows how to configure the maven project in Jenkins. Follow these steps for the 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)
Image1-CMD-screen

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)
Image2-JenkinsStartUpScreen


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

Untitled

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

UntitledGCS
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

Image5-configureSystem
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

Image7-JobConfigure1

– 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”

Image7-JobConfigure2

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 the build succeeds”
g) In Post Build Action, add post-build action and give the job name(4503_deploy) in “Projects to build

Image7-JobConfigure3
 

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.

Source:
https://www.tothenew.com/blog/how-to-setup-jenkins-for-a-maven-project/

aem4beginner.blogspot


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.

Ad Blocker Detected :(

Please consider supporting us by disabling your ad blocker.

Please Disable your adblocker and Refresh the page to view the site content.