美好的一天,
我的Jenkins文件中有以下代码:
finally {
try {
sh "cat \"${report_file}\""
junit "${report_file}"
}
catch (e) {
echo "ERROR: Can't operate junit xml results'"
echo e.toString()
}
}
结果是当运行时:
> [] Running shell script cat
> '/var/lib/jenkins/workspace//Sanity/authenticate/keystone.json/report.junit.xml'
> <testsuites> <!--Report is generated by Rally 0.10.1~dev35 at
> 2017-12-08T18:26:40--> <testsuite errors="0" failures="0"
> id="" skipped="0" tests="1"
> time="15.00" timestamp="2017-12-08T18:26:17">
> <testcase classname="Authenticate" id="" name="keystone" time="2.78"
> timestamp="2017-12-08T18:26:27" /> </testsuite> </testsuites>
>
> [Pipeline] junit Recording test results [Pipeline] echo ERROR: Can't
> operate junit xml results' [Pipeline] echo hudson.AbortException: No
> test report files were found. Configuration error?
报告在那里,但是junit步骤无法读取变量。这可能吗?
非常感谢
答案 0 :(得分:2)
不要指定测试结果文件的绝对路径。这在某种程度上不适用于junit
步骤。
以下代码适用于我:
node {
// def path = env.WORKSPACE + '/junit.xml'
def path = 'junit.xml'
writeFile file: path, text: '<testsuites><!--Report is generated by Rally 0.10.1~dev35 at 2017-12-08T18:26:40--> <testsuite errors="0" failures="0" id="" skipped="0" tests="1" time="15.00" timestamp="2017-12-08T18:26:17"><testcase classname="Authenticate" id="" name="keystone" time="2.78" timestamp="2017-12-08T18:26:27" /></testsuite></testsuites>'
echo path
junit path
}
带输出
Running on Jenkins in /var/jenkins_home/workspace/Pipeline
[Pipeline] {
[Pipeline] writeFile
[Pipeline] echo
junit.xml
[Pipeline] junit
Recording test results
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
使用绝对path
:
node {
def path = env.WORKSPACE + '/junit.xml'
// def path = 'junit.xml'
writeFile file: path, text: '<testsuites><!--Report is generated by Rally 0.10.1~dev35 at 2017-12-08T18:26:40--> <testsuite errors="0" failures="0" id="" skipped="0" tests="1" time="15.00" timestamp="2017-12-08T18:26:17"><testcase classname="Authenticate" id="" name="keystone" time="2.78" timestamp="2017-12-08T18:26:27" /></testsuite></testsuites>'
echo path
junit path
}
junit
步骤失败以查找测试结果:
Running on Jenkins in /var/jenkins_home/workspace/Pipeline
[Pipeline] {
[Pipeline] writeFile
[Pipeline] echo
/var/jenkins_home/workspace/Pipeline/junit.xml
[Pipeline] junit
Recording test results
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: No test report files were found. Configuration error?
Finished: FAILURE