Jenkins-GitHub with Java Maven Project

Amit Verma
4 min readNov 4, 2018

--

Jenkins | GitHub | Java | CI | Automation

Let’s assume a scenario — when a developer completed its coding part on its local machine. To keep versioning of source code he/she committed code to some VCS (let say GitHub). At the end of the day developer want to see the running integrated code on Dev Server situated somewhere, then developer has to manually build his code and put it to Dev server.

For above case we will use the automated solution. Developer commits code to GitHub then Jenkins will automatically pull the code from GitHub and automatically builds the project.

Make sure that Jenkins is properly setup and Maven project is on GitHub.

Step 1: Configure Jenkins

  1. Insure that GitHub Plugin is installed under- Manage Jenkins > Manage Plugins > Installed search for git. If not installed move to Available Tab and search for git and install it.
  2. Configure Java, GitHub and Maven for Jenkins
  3. Navigate to Manage Jenkins > Global Tool Configuration > Under JDK section provide Name and path to JAVA_HOME, in same way for Git provide Git Name and path to Git executable, same in case of Maven provide Name and MAVEN_HOME as in below images

Step 2: Create Job

  1. Create a new Job by clicking New Item
  2. Enter your Job Name ‘Jenkins-GitHub’ and select Maven Project then click OK, You will be navigated to configure the Job.

If Maven Project is not visible in your Jenkins then install plugin named as ‘Maven Integration’

3. In job configuration under General Section tick Github project and provide your project url from Github- https://github.com/amitvermaa93/jenkins-git-integration.git this will provide you link to GitHub from Job dashboard and it is optional

4. Under Source Code Management section click on Git radio button and provide Repository URL- https://github.com/amitvermaa93/jenkins-git-integration.git

5. Select branch to build if master- ‘*/master’ if development- ‘*/development’

6. You can add behavior by selecting value from drop down what to perform in my case I want to clean space before code checkout so I have selected Clean before chekout (you can configure according to your need this is optional)

7. Navigate to Build Trigger- If you want to build your project on specific time interval you can configure it under Build Trigger > tick Poll SCM and in text field * * * * * (five star separated by space for every minute, see bottom of this article for convention). If you will not set up Poll you will have to manually build the Job.

8. Navigate to Build Section > provide path to pom.xml (for maven project) and Goals and Options (you can provide relative or absolute path to pom.xml, Relative : from project checkout directory as in below image, Absolute : from base directory like C:\Users\Amit Verma\.jenkins\workspace\Jenkins-GitHub\pom.xml and for goals you can define as you have set in your pom.xml like clean, package, etc)

Navigate to that project. You will have to click on Build Now if you have not configured Poll SCM else it will automatically trigger every minute (as we have set * * * * *). Your project will build successfully.

Go to project path (C:\Users\Amit Verma\.jenkins\workspace\Jenkins-GitHub\target) and under target you will find the jar or war of your build project.

By clicking on blue circle you will be able to see logs.

By Clicking #1 (#<Build Number>) you will be navigation to below window showing various project related information.

Poll SCM:

(* * * * * ) represents (minute, hour, day_of_month, week, day_of_week)

range (0–59, 0–23, 1–31, 1–12, 0–7)

sunday -0, monday-1, tuesday-2 ,…,saturday-6

January-1, Feb-2, …,Dec-12

Example :

  • /5 * * * * — every 15 min
  • 0 * * * * — every hour
  • 0 0 * * * — every 00:00 hours
  • 00 14 10 3,6,9,12 * — at 2:00 PM on 10th of March, June, September and December
  • 25,50 1 15 * 2 — at 1:25 AM, 1:50 AM every Tuesday and on 15th of every month.
  • 00 21 * * Mon,Wed,Fri — at 9.00 PM every Monday, Wednesday, Friday
  • */5 * * * 1–5 — every 5 minutes during the 5 working days (Monday — Friday), every week and month
  • * */4 * * Sun — every minute past every 4th hour on Sunday

--

--