首页 > 解决方案 > gitlab ci:JUnit XML 解析失败:致命:文档末尾有额外内容

问题描述

我正在尝试在我的管道中创建单元测试报告,但我收到了这个错误。奇怪的是,有时当我对代码进行某些更改时,报告会成功解析,但在第二次运行时会发生此错误。我尝试了清除缓存之类的方法,但它不起作用。

ci.yaml 看起来像这样

build-job:
  image: $IMAGE_REPO/$image:$version
  script:
  - ./build-and-test.sh
  artifacts:
    when: always
    reports:
      junit: 
        - $CI_PROJECT_DIR/build-dir/src/tests/reports/*.xml

build-and-test.sh 运行这个命令来运行测试:

 ctest --output-on-failure -j 16 -R 'CI|Ci' 

这会生成超过 100 个报告文件夹的 xml 报告,每个报告的名称类似于 <my_project> test .xml

每个文件都有以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failures="0" disabled="0" errors="0" time="0.069" timestamp="2021-06-08T22:51:07" name="AllTests">
  <testsuite name="<test_name>" tests="1" failures="0" disabled="0" errors="0" time="0.069" timestamp="2021-06-08T22:51:07">
    <testcase name="<test_case_name>" status="run" result="completed" time="0.069" timestamp="2021-06-08T22:51:07" classname="<test_name>" />
  </testsuite>
</testsuites>

我使用 xml 检查器https://www.xmlvalidation.com/index.php?id=1&L=0检查这些 xml 文件的语法,它没有返回错误。我想知道我做错了什么?junit 解析器不是要一次解析多个文件吗?

标签: xmljunitgitlabgitlab-ci

解决方案


推荐阅读