Search code examples
jsonjenkinscoberturaistanbullcov

Cannot generate a cobertura.xml file from lcov.info or coverage.json file in Jenkins VirtualEnv


I have a ready javascript file that run all unit tests and coverage. And the script is generating coverage.json file. I favor using the cobertura plugin (https://wiki.jenkins-ci.org/display/JENKINS/Cobertura+Plugin) so I was looking for a solution to create the cobertura-suitable file format which is xml.

I do everything in VirutalEnv(https://wiki.jenkins-ci.org/display/JENKINS/ShiningPanda+Plugin)!

I tried this command:istanbul report cobertura --root $WORKSPACE/coverage/coverage.json --dir coverage/ (https://github.com/gotwarlost/istanbul)

And the result is as follows:

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

However, the created cobertura-coverage.xml file is almost empty!

<?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>

And the code cobertura code coverage tool shows nothing! 0!!

I also tried using the lcov-to-cobertura-xml(https://github.com/eriwen/lcov-to-cobertura-xml), but the result is as follows:

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

What am I doing wrong? Wasted so many hours trying to solve this!!! Maybe I should use another tool that can transform the coverage.json file into chart or graph visualisation of code coverage?


Solution

  • Ok I found a solution...

    My command was: istanbul report cobertura --root $WORKSPACE/coverage/coverage.json --dir coverage/

    I changed it to istanbul report cobertura --root $WORKSPACE/coverage --dir $WORKSPACE

    And now it works perfectly. The issue was probably setting the root and dir to the same folder. No idea why it worked that way but hey, it's solved :).