如何获取在Jenkins中使用JUnit XML格式在后期作业脚本中运行的测试数量? [英] How to get the number of tests run in Jenkins with JUnit XML format in the post job script?
问题描述
有没有办法获得在Jenkins中在后作业脚本中执行(或传递)的测试数量(例如,将此数字发送到Github Status API )? / p>
Is there any way to get the number of tests that were executed (or passed) in Jenkins in a Post Job Script (for example, to send this number to the Github Status API)?
推荐答案
我没有看到任何方法直接从发布JUnit测试结果报告
Jenkins插件。
I didn't see any way to access these numbers directly from Publish JUnit test result report
Jenkins plug-in.
但是,在成功解析JUnit XML之后,您可以随时使用/解析Jenkins REST API中的xml或json:
However, you can always use/parse the xml or json taken form Jenkins REST API after successfully parsing the JUnit XML:
http://< jenkinsHost> / job /< YourJobName> /< JobID> / testReport / api / json?pretty = true
或
使其更通用:
http://< jenkinsHost> / job /< YourJobName> / lastSuccessfulBuild / testReport / api / json?pretty = true
用于JSON输出:
{
"duration" : 6109.1104,
"failCount" : 0,
"passCount" : 4389,
"skipCount" : 0,
"suites" : [
{
"cases" : [
{
...
}
],
"duration" : 0.012,
"id" : null,
"name" : "EventTest",
"stderr" : null,
"stdout" : null,
"timestamp" : null
}
]
}
http://< jenkinsInstanceHost> / job /< YourJobName> /< JobID> / testReport / api / xml
用于XML输出:
<testResult>
<duration>6109.1104</duration>
<failCount>0</failCount>
<passCount>4389</passCount>
<skipCount>0</skipCount>
<suite>
<case>
<age>0</age>
<className>
...
</className>
<duration>0.012</duration>
<failedSince>0</failedSince>
<name>Loop</name>
<skipped>false</skipped>
<status>PASSED</status>
</case>
<duration>0.012</duration>
<name>EventTest</name>
</suite>
</testResult>
这篇关于如何获取在Jenkins中使用JUnit XML格式在后期作业脚本中运行的测试数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!