Simplify test reporting
Closed this issue · 1 comments
Your current example suggests something like
def allTests() {
mvn 'test -B'
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
if (currentBuild.result == "UNSTABLE") {
sh "exit 1"
}
}
def mvn(args) {
sh "mvn ${args} -Dmaven.test.failure.ignore -Dmaven.repo.local=/github/workspace/.m2"
}
which does not make much sense to me. First you are running Maven and telling it to accept test failures; then you are running the Jenkins publisher for tests, which is only useful for setting a build status since the actual reports are discarded as soon as the container exits; then you are causing the build to fail if there were results. This could all be done more simply:
def allTests() {
mvn 'test -B'
}
def mvn(args) {
sh "mvn ${args} -Dmaven.repo.local=/github/workspace/.m2"
}
letting Surefire fail the build if there are any test failures—its default behavior.
(Also BTW the -B
argument could be pushed down into the mvn
function.)
@jglick: The Jenkinsfile shown was a very stripped down version of a bigger project which had more sophisticated conditions around, see https://gist.github.com/jonico/e205b16cf07451b2f475543cf1541e70
I will go ahead and make the changes you suggested