I'm using groovy in jenkins pipeline scripts. How i can take the results of falling unit tests from junit report file? Now i'm trying to get them by code:
import hudson.tasks.junit.TestResultAction
import hudson.model.*
import java.*
import java.lang.*
import hudson.*
import hudson.model.*
import jenkins.model.Jenkins
...some code ...
dir (workspace){
step([$class: 'JUnitResultArchiver', keepLongStdio: true, testResults: "artifacts/*/*.xml"])
result_junit = count_fail_unit_tests()
echo "UNIT TESTS FAIL COUNT: ${result_junit}"
if (result_junit != 0){
currentBuild.displayName = "UNIT TESTS FAIL"
}
throw new Exception("warning_exception")
}
archiveArtifacts allowEmptyArchive: true, artifacts: "log/*", caseSensitive: false
}
@NonCPS
def count_fail_unit_tests() {
def count_fail_tests = manager.build.getAction(hudson.tasks.junit.TestResultAction.class).getFailCount()
return count_fail_tests
}
and got an error
ERROR: groovy.lang.MissingPropertyException: No such property: manager for class: Script4
Earlier i got the count of errors by code:
dir (workspace){
result_junit = junit keepLongStdio: true, testResults: "artifacts/*/*.xml"
echo "UNIT TESTS FAIL COUNT: ${result_junit}"
if (result_junit != 0){
currentBuild.displayName = "UNIT TESTS FAIL"
}
throw new Exception("warning_exception")
}
archiveArtifacts allowEmptyArchive: true, artifacts: "log/*", caseSensitive: false
}
and it was working, but it had bug:
if use junit keepLongStdio: true, testResults: "artifacts/*/*.xml"
and report .xml file has incorrect structure, building not failing and stay in status "SUCCESS".
With using step([$class: 'JUnitResultArchiver', keepLongStdio: true, testResults: "artifacts/*/*.xml"])
it fails, thats why i want to use this metod.
If i try
some_return = step([$class: 'JUnitResultArchiver', keepLongStdio: true, testResults: "artifacts/*/*.xml"])
echo "${some_return}"
get
null
Is there some metods for junit keepLongStdio: true, testResults: "artifacts/*/*.xml"
to fail build, if xml junit report is incorrect?
Or how i can take counts from
step([$class: 'JUnitResultArchiver', keepLongStdio: true, testResults: "artifacts/*/*.xml"])