Thursday, January 18, 2018

CI/CD with Baby Steps (Jenkins - Build with Maven Project)

In last tutorial we automate our Eclipse Project build process with default "Freestyle Project" option of Jenkins, in which we scheduled build process with shell commands.

In this tutorial we will explore Jenkins "Maven Project" options.

Maven is a build / project management tool, based on the concept of a project object model (POM) which contains every information about your project. Maven allows a project to build using its project object model to manage builds, dependencies, releases and documentation which are all managed from the pom.xml file

In Jenkins 2.101 Maven Project is not available with default installation so we have to install plugin "Maven Integration plugin", So install plugin accordingy.

Maven Integration plugin
"This plug-in provides, for better and for worse, a deep integration of Jenkins and Maven:
Automatic triggers between projects depending on SNAPSHOTs, automated configuration of
various Jenkins publishers (Junit, ...)."

If Maven is not configured in Jenkins, Please configure

Configuring System
Go to Manage Jenkins-> Global Tool Configuration
1 - Configure JDK
-Give the JDK name
-JAVA_HOME : C:\Java\jdk1.8.0_121

2 - Maven configuration
-Give a maven name
-MAVEN_HOME : C:\Apache\apache-maven-3.5.0

Step 1 : Jenkins - New Item - Enter an Item name (any name) - select Maven project - click OK

it will show multi Tab windows

Step 2 : In General Tab provide description

Step 3 : In Source Code Management Tab, Jenkins supports CVS and Subversion out of the box, with built-in support for Git, and also integrates with many other version control systems via plugins. We will look into these details in next tutorials. Now lets make it simple and select 'None' to execute from local machine.

Step 4 : Build Triggers Tab, We have multiple options like 'Build periodically', 'Poll SCM', 'Build whenever a SNAPSHOT dependency is built, etc. Example, if you select 'Poll SCM' option, Jenkins will poll the repository for changes based on the cron expression specified. we will select
"Build periodically" which support Cron like job schedule like after 15 min or once a day.
As of now we will start with after every 5 minutes and put "H/5 * * * *" in schedule Text Field.

Step 5 : In Build, We need to tell Jenkins where to find pom.xml file. Please specify the path of your pom.xml file in Build Root POM and Specify 'Goals and options', in this example 'clean test'.
Root Pom: C:\Users\imran\workspace\GreenFarm\pom.xml
Goals and options: package

Step 6:- In Build Settings, If you want to send an email notifications, you can check 'Email Notification' and add Recipients address.

No comments: