How to fail a Maven build if unit tests fail?

3,078 views
Skip to first unread message

Dave

unread,
Oct 9, 2012, 5:14:00 PM10/9/12
to jenkins...@googlegroups.com

Hi,

I just installed the latest version of Jenkins on CentOS.  For all my Maven projects, I want the build to indicate failure if a single test fails.  So I tried editing the global MAVEN_OPTS by navigating to the configuration page ...

Jenkins -> Manage Jenkins -> Configure System

and under the "Maven Project Configuration" section I've set the "Global MAVEN_OPTS" to "-Djava.awt.headless=true -Dmaven.test.failure.ignore=false".  I set the second option because I want to globally indicate that all projects should indicate failure if a single JUnit test fails.  However, after restarting Jenkins, in my multi-module project, this is not happening.  That is, there are test failures yet the project is indicating success.

Is there another global way I can tell Jenkins to fail a Maven project if there are test failures?

Thanks, - Dave

Thomas Sundberg

unread,
Oct 10, 2012, 1:27:41 AM10/10/12
to jenkins...@googlegroups.com
Setting the MAVEN_OPTS to

-Dmaven.test.failure.ignore=false

is the way I have used successfully.

Can you get a smaller Maven project to fail? A single module, one test
case that just does fail()?
Maybe set it to the individual project and see what happens?
Could you remove the headless setting to see if there is any change?

HTH
Thomas

--
Thomas Sundberg
M. Sc. in Computer Science

Mobile: +46 70 767 33 15
Blog: http://thomassundberg.wordpress.com/
Twitter: @thomassundberg

Better software through faster feedback

Dave

unread,
Oct 10, 2012, 12:59:10 PM10/10/12
to jenkins...@googlegroups.com
I had a project-specific MAVEN_OPTS setting and changing the global MAVEN_OPTS setting didn't affect the project specific one.  Adjusting the project specific one fixed my problem.

Interestingly, when I created a new Maven2/3 job, the job's MAVEN_OPTS setting was already populated with "-Djava.awt.headless=true".  Not sure where this came from as my global setting is "-Dmaven.test.failure.ignore=false".  Another problem for another day, - 
Reply all
Reply to author
Forward
0 new messages