Jenkins Groovy为成功运行找到空testResultAction的脚本 [英] Jenkins Groovy Script finding null testResultAction for a successful run
问题描述
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:红色','FAIL')
}
...
}
}
其他{
tr(){
td(project.name)
td(){
b(style:'color:red',PASS)
}
...
}
}
}
}
}
通常一切运行良好,但最近有一两次特定的构建已经开始一致返回,因为没有结果,即它们的.testResultAction为null。我已经检查了testResultAction的实际值,尽管他们运行的是一个干净的测试,但Jenkins本身也是这样认为的,但它确实是null。
测试已重新-ran,詹金斯被删除并重新制作;没有帮助。这个问题似乎困扰着某些不相关的构建。 Jenkins在这里有一个特定的缺陷,我应该知道这会导致testResultAction默认为null并且不会更改?否则,任何人都可以提出什么可能会导致这种情况发生,或者我可以如何阻止它? 解决方案
也给我零。我获得了更多的成功:
project.lastBuild.getAction(hudson.tasks.test.AggregatedTestResultAction.class)
虽然它可以为空,只是因为项目中没有测试。
无论如何,这里有一个测试结果的方法,适用于我。
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} \\\
+
name:$ {test.name} \ n+
age:$ {test.age} \\\
+
failCount:$ {test.failCount} \\\
+
failedSince:$ {test。 }
errorDetails:$ {test.errorDetails} \\\
)
}
}
}
}
We have an email report writer for test suites on jenkins. It uses a groovy script to find the correct reports and then make an HTML report detailing the test status, last time ran, 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 runs fine, but recently one or two specific builds have started to be returned consistently as "No results" i.e. their .testResultAction is null. I've checked the actual value for testResultAction, and it is indeed a null, despite them running a clean test that Jenkins itself recognises as such.
The tests have been re-ran, and the jenkins build deleted and remade; neither helped. This problem seems to be haunting certain, unrelated, builds. Is there a particular flaw in Jenkins here that I should know about that causes the testResultAction to default to null and not change? Otherwise, can anyone suggest what might be causing this to happen, or how I can stop it?
That method is deprecated and was giving me null too. I had more success with this:
project.lastBuild.getAction(hudson.tasks.test.AggregatedTestResultAction.class)
Though it can be null just because there are no tests in the project. Anyway, here's a method for testing the results, which 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")
}
}
}
}
这篇关于Jenkins Groovy为成功运行找到空testResultAction的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!