Question

How can I fail Maven build if surefire:test goal fails? I am asking this question in the context of running tests, excuted by Maven Surefire, on Jenkins. Currently, if 1 or all tests fail, Jenkins reports "unstable build" instead of a red error. How can I override this and tell Maven to return a failure exit code if 1 or more tests fail? I want Jenkins to report a RED icon instead of a YELLOW icon.

Was it helpful?

Solution

You can separate your compile and test phases, using the post-build task plugin. That has an option "Escalate script execution status to job status", which will do what you want. So you might use goal compile or process-test-classes for your build, and your post-build task would be mvn verify with the escalate option turned on.

OTHER TIPS

Click on the legend button of your Jenkins instance ( main view, lower right corner), it'll show you something like https://builds.apache.org/legend In general: red is compilation error(fatal), yellow means failing tests. So those colors have different meanings, which should help you to identify the problem. The actual question is: Why do you want yellow to be red?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top