如何将 newman 集合测试结果合并到一个有效的 xml 文件中供 Jenkins 使用?
How to combine newman collection test results into one valid xml file for Jenkins?
我有一个小型 Jenkins 管道,它按顺序测试不同的 Postman 集合,然后我将单个 XML 文件合并为一个,然后将它们作为结果传递给 Jenkins。
管道片段:
...
steps {
script {
try {
sh '(cd ./integrativeTests/collections && rm -rf *.xml)'
sh '(cd ./integrativeTests/collections && npm run tests-all)'
sh '''
cd ./integrativeTests/collections
echo '<?xml version="1.0" encoding="UTF-8"?>' > newman_dev_results.xml
echo '<testsuites>' >> newman_dev_results.xml
for f in COLLECTION-*.xml
do
echo $(sed 1,$(expr $(grep -m1 -n "<testsuite" ${f} | cut -f1 -d:) - 1)d ${f}) >> newman_dev_results.xml
done
echo '</testsuites>' >> newman_dev_results.xml
cat newman_dev_results.xml
'''
sh '(cp ./integrativeTests/collections/newman_dev_results.xml ./newman_results.xml)'
currentBuild.result = 'SUCCESS'
} catch(Exception e) {
currentBuild.result = 'FAILURE'
}
junit 'newman_results.xml'
}
}
...
结果 XML 如下所示:
但遗憾的是我在 Jenkins 日志中收到错误消息:
ERROR: None of the test reports contained any result
Finished: FAILURE
Jenkins 的多个集合的测试结果的正确 xml 布局是什么,或者我如何将多个测试结果传递给 Jenkins?
如 official docs of the Junit Plugin 中所见,我不需要自己组合所有 xml 并传递单个文件。我只需要使用通配符一次传递所有 XML。
管道:
...
steps {
script {
try {
sh '(cd ./integrativeTests/collections && npm run tests-all)'
currentBuild.result = 'SUCCESS'
} catch(Exception e) {
currentBuild.result = 'FAILURE'
}
sh 'junit-viewer --results=./integrativeTests/collections --save=result.html'
archiveArtifacts artifacts: 'result.html', fingerprint: true
junit '**/integrativeTests/collections/COLLECTION-*.xml'
}
}
...
我有一个小型 Jenkins 管道,它按顺序测试不同的 Postman 集合,然后我将单个 XML 文件合并为一个,然后将它们作为结果传递给 Jenkins。
管道片段:
...
steps {
script {
try {
sh '(cd ./integrativeTests/collections && rm -rf *.xml)'
sh '(cd ./integrativeTests/collections && npm run tests-all)'
sh '''
cd ./integrativeTests/collections
echo '<?xml version="1.0" encoding="UTF-8"?>' > newman_dev_results.xml
echo '<testsuites>' >> newman_dev_results.xml
for f in COLLECTION-*.xml
do
echo $(sed 1,$(expr $(grep -m1 -n "<testsuite" ${f} | cut -f1 -d:) - 1)d ${f}) >> newman_dev_results.xml
done
echo '</testsuites>' >> newman_dev_results.xml
cat newman_dev_results.xml
'''
sh '(cp ./integrativeTests/collections/newman_dev_results.xml ./newman_results.xml)'
currentBuild.result = 'SUCCESS'
} catch(Exception e) {
currentBuild.result = 'FAILURE'
}
junit 'newman_results.xml'
}
}
...
结果 XML 如下所示:
但遗憾的是我在 Jenkins 日志中收到错误消息:
ERROR: None of the test reports contained any result
Finished: FAILURE
Jenkins 的多个集合的测试结果的正确 xml 布局是什么,或者我如何将多个测试结果传递给 Jenkins?
如 official docs of the Junit Plugin 中所见,我不需要自己组合所有 xml 并传递单个文件。我只需要使用通配符一次传递所有 XML。
管道:
...
steps {
script {
try {
sh '(cd ./integrativeTests/collections && npm run tests-all)'
currentBuild.result = 'SUCCESS'
} catch(Exception e) {
currentBuild.result = 'FAILURE'
}
sh 'junit-viewer --results=./integrativeTests/collections --save=result.html'
archiveArtifacts artifacts: 'result.html', fingerprint: true
junit '**/integrativeTests/collections/COLLECTION-*.xml'
}
}
...