Run maven with Jenkins

In post How to find out a process PID on Windows, I started Jenkins server from my laptop. It is running from http://localhost:8080/ 

And in another post Run appfuse with Maven, I have setup the Maven and other required software on my laptop. A couple of maven targets are verified as well Basic Maven lifecycle.

In this post, I integrated maven (clean, build, test, and install) with Jenkins as what I did in Basic Maven lifecycle.

Jenkins is a very friendly CI platform. Build engineer can setup almost everything just via its UI.

1. Define a job

definejob

 

The configuration file will be stored in C:\Users\luhuang\.jenkins\jobs

C:\Users\luhuang\.m2\repository\HelloWorld\helloworld\1.0>cd C:\Users\luhuang\.j
enkins\jobs

C:\Users\luhuang\.jenkins\jobs>dir
Volume in drive C is System
Volume Serial Number is 4499-5BD0

Directory of C:\Users\luhuang\.jenkins\jobs

06/29/2014 12:24 AM <DIR> .
06/29/2014 12:24 AM <DIR> ..
06/29/2014 12:02 AM <DIR> HelloWorld-Build
06/29/2014 12:05 AM <DIR> HelloWorld-Clean
06/29/2014 12:24 AM <DIR> HelloWorld-Full
06/29/2014 12:14 AM <DIR> HelloWorld-Install
06/29/2014 12:11 AM <DIR> HelloWorld-Test
0 File(s) 0 bytes
7 Dir(s) 53,380,505,600 bytes free

C:\Users\luhuang\.jenkins\jobs>

C:\Users\luhuang\.jenkins\jobs\HelloWorld-Clean>dir
Volume in drive C is System
Volume Serial Number is 4499-5BD0

Directory of C:\Users\luhuang\.jenkins\jobs\HelloWorld-Clean

06/29/2014 12:05 AM <DIR> .
06/29/2014 12:05 AM <DIR> ..
06/29/2014 12:06 AM <DIR> builds
06/29/2014 12:05 AM 1,697 config.xml
06/28/2014 11:50 PM <DIR> modules
06/29/2014 12:05 AM 2 nextBuildNumber
06/28/2014 11:50 PM <DIR> workspace
2 File(s) 1,699 bytes
5 Dir(s) 53,380,505,600 bytes free

C:\Users\luhuang\.jenkins\jobs\HelloWorld-Clean>

One of the configuration file of a job,


<?xml version='1.0' encoding='UTF-8'?>
<maven2-moduleset plugin="maven-plugin@2.3">
 <actions/>
 <description>It is a demo job to demonstrate how to run maven targets as Jenkins job. It includes clean, build, test, install and deploy.</description>
 <keepDependencies>false</keepDependencies>
 <properties/>
 <scm class="hudson.scm.NullSCM"/>
 <canRoam>true</canRoam>
 <disabled>false</disabled>
 <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
 <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
 <triggers/>
 <concurrentBuild>false</concurrentBuild>
 <rootModule>
 <groupId>HelloWorld</groupId>
 <artifactId>helloworld</artifactId>
 </rootModule>
 <rootPOM>D:\Source\helloworld-master\pom.xml</rootPOM>
 <goals>clean</goals>
 <aggregatorStyleBuild>true</aggregatorStyleBuild>
 <incrementalBuild>false</incrementalBuild>
 <ignoreUpstremChanges>true</ignoreUpstremChanges>
 <archivingDisabled>false</archivingDisabled>
 <siteArchivingDisabled>false</siteArchivingDisabled>
 <resolveDependencies>false</resolveDependencies>
 <processPlugins>false</processPlugins>
 <mavenValidationLevel>-1</mavenValidationLevel>
 <runHeadless>false</runHeadless>
 <disableTriggerDownstreamProjects>false</disableTriggerDownstreamProjects>
 <settings class="jenkins.mvn.DefaultSettingsProvider"/>
 <globalSettings class="jenkins.mvn.DefaultGlobalSettingsProvider"/>
 <reporters/>
 <publishers/>
 <buildWrappers/>
 <prebuilders/>
 <postbuilders/>
 <runPostStepsIfResult>
 <name>SUCCESS</name>
 <ordinal>0</ordinal>
 <color>BLUE</color>
 <completeBuild>true</completeBuild>
 </runPostStepsIfResult>
</maven2-moduleset>

The file nextBuildNumber stores the latest build version.

2. Defined a couple of jobs

buildstatus

3. Check log

SuccessConsole Output

Started by user anonymous
Building in workspace C:\Users\luhuang\.jenkins\jobs\HelloWorld-Install\workspace
Parsing POMs
Discovered a new module HelloWorld:helloworld HelloWorld
Modules changed, recalculating dependency graph
[helloworld-master] $ C:\glassfish4\jdk7/bin/java -cp C:\Users\luhuang\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven31-agent-1.5.jar;D:\apache-maven-3.2.2\boot\plexus-classworlds-2.5.1.jar;D:\apache-maven-3.2.2/conf/logging jenkins.maven3.agent.Maven31Main D:\apache-maven-3.2.2 C:\Users\luhuang\.jenkins\war\WEB-INF\lib\remoting-2.43.jar C:\Users\luhuang\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven31-interceptor-1.5.jar C:\Users\luhuang\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven3-interceptor-commons-1.5.jar 52835
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven:  -B -f D:\Source\helloworld-master\pom.xml install
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building HelloWorld 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ helloworld ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Source\helloworld-master\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ helloworld ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ helloworld ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Source\helloworld-master\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ helloworld ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ helloworld ---
[INFO] Surefire report directory: D:\Source\helloworld-master\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running HelloWorldTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.039 sec

Results :

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

[JENKINS] Recording test results
log4j:WARN No appenders could be found for logger (org.apache.commons.beanutils.converters.BooleanConverter).
log4j:WARN Please initialize the log4j system properly.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ helloworld ---
[INFO] Building jar: D:\Source\helloworld-master\target\helloworld-1.0.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ helloworld ---
[INFO] Installing D:\Source\helloworld-master\target\helloworld-1.0.jar to C:\Users\luhuang\.m2\repository\HelloWorld\helloworld\1.0\helloworld-1.0.jar
[INFO] Installing D:\Source\helloworld-master\pom.xml to C:\Users\luhuang\.m2\repository\HelloWorld\helloworld\1.0\helloworld-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.517 s
[INFO] Finished at: 2014-06-29T00:15:01+08:00
[INFO] Final Memory: 15M/224M
[INFO] ------------------------------------------------------------------------
[JENKINS] Archiving D:\Source\helloworld-master\pom.xml to HelloWorld/helloworld/1.0/helloworld-1.0.pom
[JENKINS] Archiving D:\Source\helloworld-master\target\helloworld-1.0.jar to HelloWorld/helloworld/1.0/helloworld-1.0.jar
channel stopped
Finished: SUCCESS