无法从 Jenkins VirtualEnv 中的 lcov.info 或 coverage.json 文件生成 cobertura.xml 文件
Cannot generate a cobertura.xml file from lcov.info or coverage.json file in Jenkins VirtualEnv
我有一个准备好的 javascript 文件,其中 运行 所有单元测试和覆盖率。脚本正在生成 coverage.json 文件。我喜欢使用 cobertura 插件 (https://wiki.jenkins-ci.org/display/JENKINS/Cobertura+Plugin),所以我一直在寻找一种解决方案来创建适合 cobertura 的文件格式,即 xml.
我在 VirutalEnv(https://wiki.jenkins-ci.org/display/JENKINS/ShiningPanda+Plugin) 中做所有事情!
我试过这个命令:istanbul report cobertura --root $WORKSPACE/coverage/coverage.json --dir coverage/
(https://github.com/gotwarlost/istanbul)
结果如下:
13:26:09 [...]
13:26:09 210 passing (1s)
13:26:09
13:26:09 =============================================================================
13:26:09 Writing coverage object [/var/lib/jenkins/workspace/unit-tests-client-javascript/coverage/coverage.json]
13:26:09 Writing coverage reports at [/var/lib/jenkins/workspace/unit-tests-client-javascript/coverage]
13:26:09 =============================================================================
13:26:09
13:26:09 =============================== Coverage summary ===============================
13:26:09 Statements : 96.88% ( 279/288 )
13:26:09 Branches : 86.24% ( 94/109 ), 1 ignored
13:26:09 Functions : 100% ( 57/57 )
13:26:09 Lines : 96.88% ( 279/288 )
13:26:09 ================================================================================
13:26:11 + istanbul report cobertura --root /var/lib/jenkins/workspace/unit-tests-client-javascript/coverage/coverage.json --dir coverage/
13:26:11 Done
13:26:11 [Cobertura] Publishing Cobertura coverage report...
13:26:11 Publishing Cobertura coverage results...
13:26:11 Cobertura coverage report found.
13:26:11 Finished: SUCCESS
然而,创建的cobertura-coverage.xml文件几乎是空的!
<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage lines-valid="0" lines-covered="0" line-rate="1" branches-valid="0" branches-covered="0" branch-rate="1" timestamp="1483968808589" complexity="0" version="0.1">
<sources>
<source>/var/lib/jenkins/workspace/unit-tests-client-javascript</source>
</sources>
<packages>
</packages>
而 code cobertura 代码覆盖工具什么也没显示! 0!!
我也试过使用lcov-to-cobertura-xml(https://github.com/eriwen/lcov-to-cobertura-xml),结果如下:
14:33:24 [...]
14:33:24 + git clone https://github.com/eriwen/lcov-to-cobertura-xml.git
14:33:24 Cloning into 'lcov-to-cobertura-xml'...
14:33:27 + pip install /var/lib/jenkins/workspace/unit-tests-client-javascript/lcov-to-cobertura-xml/.
14:33:27 Processing ./lcov-to-cobertura-xml
14:33:27 Requirement already satisfied (use --upgrade to upgrade): lcov-cobertura==1.6 from file:///var/lib/jenkins/workspace/unit-tests-client-javascript/lcov-to-cobertura-xml in /var/lib/jenkins/shiningpanda/jobs/e24105b6/virtualenvs/d41d8cd9/lib/python2.7/site-packages
14:33:27 Building wheels for collected packages: lcov-cobertura
14:33:27 Running setup.py bdist_wheel for lcov-cobertura: started
14:33:28 Running setup.py bdist_wheel for lcov-cobertura: finished with status 'done'
14:33:28 Stored in directory: /var/lib/jenkins/.cache/pip/wheels/06/91/3e/ead128a367068e0e33fd380f090030c829dff190d4099a2e3b
14:33:28 Successfully built lcov-cobertura
14:33:28 + lcov_cobertura coverage/lcov.info --base-dir /var/lib/jenkins/workspace/unit-tests-client-javascript --excludes /var/lib/jenkins/workspace/unit-tests-client-javascript/test --output coverage/coverage.xml
14:33:28 /tmp/shiningpanda2010602884229553447.sh: line 40: lcov_cobertura: command not found
14:33:28 Build step 'Virtualenv Builder' marked build as failure
14:33:28 Finished: FAILURE
我做错了什么?浪费了很多时间试图解决这个问题!!!也许我应该使用另一种工具,可以将 coverage.json 文件转换为代码覆盖率的图表或图形可视化?
好的,我找到了解决方案...
我的命令是:istanbul report cobertura --root $WORKSPACE/coverage/coverage.json --dir coverage/
我改成了istanbul report cobertura --root $WORKSPACE/coverage --dir $WORKSPACE
现在可以完美运行了。问题可能是将 root 和 dir 设置到同一个文件夹。不知道为什么会这样,但是嘿,它已经解决了:)。
我有一个准备好的 javascript 文件,其中 运行 所有单元测试和覆盖率。脚本正在生成 coverage.json 文件。我喜欢使用 cobertura 插件 (https://wiki.jenkins-ci.org/display/JENKINS/Cobertura+Plugin),所以我一直在寻找一种解决方案来创建适合 cobertura 的文件格式,即 xml.
我在 VirutalEnv(https://wiki.jenkins-ci.org/display/JENKINS/ShiningPanda+Plugin) 中做所有事情!
我试过这个命令:istanbul report cobertura --root $WORKSPACE/coverage/coverage.json --dir coverage/
(https://github.com/gotwarlost/istanbul)
结果如下:
13:26:09 [...]
13:26:09 210 passing (1s)
13:26:09
13:26:09 =============================================================================
13:26:09 Writing coverage object [/var/lib/jenkins/workspace/unit-tests-client-javascript/coverage/coverage.json]
13:26:09 Writing coverage reports at [/var/lib/jenkins/workspace/unit-tests-client-javascript/coverage]
13:26:09 =============================================================================
13:26:09
13:26:09 =============================== Coverage summary ===============================
13:26:09 Statements : 96.88% ( 279/288 )
13:26:09 Branches : 86.24% ( 94/109 ), 1 ignored
13:26:09 Functions : 100% ( 57/57 )
13:26:09 Lines : 96.88% ( 279/288 )
13:26:09 ================================================================================
13:26:11 + istanbul report cobertura --root /var/lib/jenkins/workspace/unit-tests-client-javascript/coverage/coverage.json --dir coverage/
13:26:11 Done
13:26:11 [Cobertura] Publishing Cobertura coverage report...
13:26:11 Publishing Cobertura coverage results...
13:26:11 Cobertura coverage report found.
13:26:11 Finished: SUCCESS
然而,创建的cobertura-coverage.xml文件几乎是空的!
<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage lines-valid="0" lines-covered="0" line-rate="1" branches-valid="0" branches-covered="0" branch-rate="1" timestamp="1483968808589" complexity="0" version="0.1">
<sources>
<source>/var/lib/jenkins/workspace/unit-tests-client-javascript</source>
</sources>
<packages>
</packages>
而 code cobertura 代码覆盖工具什么也没显示! 0!!
我也试过使用lcov-to-cobertura-xml(https://github.com/eriwen/lcov-to-cobertura-xml),结果如下:
14:33:24 [...]
14:33:24 + git clone https://github.com/eriwen/lcov-to-cobertura-xml.git
14:33:24 Cloning into 'lcov-to-cobertura-xml'...
14:33:27 + pip install /var/lib/jenkins/workspace/unit-tests-client-javascript/lcov-to-cobertura-xml/.
14:33:27 Processing ./lcov-to-cobertura-xml
14:33:27 Requirement already satisfied (use --upgrade to upgrade): lcov-cobertura==1.6 from file:///var/lib/jenkins/workspace/unit-tests-client-javascript/lcov-to-cobertura-xml in /var/lib/jenkins/shiningpanda/jobs/e24105b6/virtualenvs/d41d8cd9/lib/python2.7/site-packages
14:33:27 Building wheels for collected packages: lcov-cobertura
14:33:27 Running setup.py bdist_wheel for lcov-cobertura: started
14:33:28 Running setup.py bdist_wheel for lcov-cobertura: finished with status 'done'
14:33:28 Stored in directory: /var/lib/jenkins/.cache/pip/wheels/06/91/3e/ead128a367068e0e33fd380f090030c829dff190d4099a2e3b
14:33:28 Successfully built lcov-cobertura
14:33:28 + lcov_cobertura coverage/lcov.info --base-dir /var/lib/jenkins/workspace/unit-tests-client-javascript --excludes /var/lib/jenkins/workspace/unit-tests-client-javascript/test --output coverage/coverage.xml
14:33:28 /tmp/shiningpanda2010602884229553447.sh: line 40: lcov_cobertura: command not found
14:33:28 Build step 'Virtualenv Builder' marked build as failure
14:33:28 Finished: FAILURE
我做错了什么?浪费了很多时间试图解决这个问题!!!也许我应该使用另一种工具,可以将 coverage.json 文件转换为代码覆盖率的图表或图形可视化?
好的,我找到了解决方案...
我的命令是:istanbul report cobertura --root $WORKSPACE/coverage/coverage.json --dir coverage/
我改成了istanbul report cobertura --root $WORKSPACE/coverage --dir $WORKSPACE
现在可以完美运行了。问题可能是将 root 和 dir 设置到同一个文件夹。不知道为什么会这样,但是嘿,它已经解决了:)。