¿Cómo puedo fallar en la compilación de Maven si falla el objetivo surefire:test?
Frecuentes
Visto 2,686 veces
2
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.
2 Respuestas
1
You can separate your compile and test phases, using the Complemento de tareas posteriores a la compilación. 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.
Respondido el 29 de enero de 14 a las 03:01
-1
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?
Respondido el 28 de enero de 14 a las 18:01
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas jenkins maven-surefire-plugin or haz tu propia pregunta.
Simple answer: this particular test suite is critical and should not allow a single error. I just want to override the default behavior of the Jenkins maven plugin, running a JUnit test, and force a exit code of 1 when there is 1 or more assertion failures ( im not talking about exceptions here) , just like I can in any shell script that I run in a Jenkins job. - djangofan
So in the end it's just a visual thing. Although I wouldn't recommend the adjustment, you can do it with wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin - Roberto Scholte
Nice suggestion. I think that will work. I'll try it. - djangofan
I don't want "yellow to be red". I want to set a higher bar. "Yellow" means caution, and I'm fine with Yellow meaning caution. A failing test, however, means that the code doesn't work. This isn't "caution". This is "this thing could delete all your files for all we know". "It compiled" is a very low bar. I understand that many developers work in an environment of constantly failing tests (or no tests at all). Our team does TDD and has zero tolerance for failing tests. - jamie
Por favor lee javaadventure.blogspot.nl/2013/11/… . The problem is that with a Maven job, Jenkins nests itself inside Maven and the surefire-plugin. And that changes the behavior when tests fail. - Roberto Scholte