Jenkins Groovy Script search null testResultAction to run successfully
We have an email report writer for test suites on jenkins. It uses a groovy script to find the correct reports and then render an HTML report detailing the test state, last run, links, etc.
hudson.model.Hudson.instance.getItems(hudson.model.FreeStyleProject).each { project ->
if(project.name.contains(searchCriteria)){
if(project.lastBuild.testResultAction == null){
tr(){
td(project.name)
td(){
b("No Results")
}
...
}
}
else{
if(project.lastBuild.testResultAction.failCount > 0){
tr(){
td(project.name)
td(){
b(style:'color:red', "FAIL")
}
...
}
}
else{
tr(){
td(project.name)
td(){
b(style:'color:red', "PASS")
}
...
}
}
}
}
}
Usually everything works fine, but recently one or two specific assemblies started to return sequentially as "No results" ie. their .testResultAction is NULL. I have checked the actual value of testResultAction and it is indeed a null value, even though they have tested a pure test that Jenkins himself admits as such.
The tests have been rerun and the Jenkins build has been removed and redone; nor helped. This problem seems to be plaguing certain, unrelated builds. Is there some peculiarity in Jenkins here that I should know about this, why testResultAction is null by default and not changed? Otherwise, can anyone suggest what might be causing this, or how can I stop it?
source to share
This method is deprecated and gave me value too. I've had more success with this:
project.lastBuild.getAction(hudson.tasks.test.AggregatedTestResultAction.class)
Though it might be null only because there are no tests in the project. Anyway, here's a method for testing the results that works for me.
def reportOnTestsForBuild(build) {
testResultAction = build.getAction(hudson.tasks.test.AggregatedTestResultAction.class);
if (testResultAction == null) {
println("No tests")
return
}
childReports = testResultAction.getChildReports();
if (childReports == null || childReports.size() == 0) {
println("No child reports")
return
}
def failures = [:]
childReports.each { report ->
def result = report.result;
if (result == null) {
println("null result from child report")
}
else if (result.failCount < 1) {
println("result has no failures")
}
else {
println("overall fail count: ${result.failCount}")
failedTests = result.getFailedTests();
failedTests.each { test ->
failures.put(test.fullDisplayName, test)
println("Failed test: ${test.fullDisplayName}\n" +
"name: ${test.name}\n" +
"age: ${test.age}\n" +
"failCount: ${test.failCount}\n" +
"failedSince: ${test.failedSince}\n" +
"errorDetails: ${test.errorDetails}\n")
}
}
}
}
source to share