Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-13889

Cobertura plugin is not able to find code from python coverage

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • cobertura-plugin
    • None

      Our repository has all src code under /src. So when running tests and coverage the coverage.xml file is generated in $WORKSPACE/src. In the job config I specify **/coverage.xml in the location. Th eCobertura plugin finds the coverage report but states:

      Source code is unavailable. Some possible reasons are:

      This is not the most recent build (to save on disk space, this plugin only keeps the most recent builds source code).
      Cobertura found the source code but did not provide enough information to locate the source code.
      Cobertura could not find the source code, so this plugin has no hope of finding it.

      I believe this is due to the fact that coverage.xml records the relative path to the files. As this file is in $WORKSPACE/src I would expect it to find the files in $WORKSPACE/src/<relative path>, but I susepct it's omitting the 'src' directory.

          [JENKINS-13889] Cobertura plugin is not able to find code from python coverage

          cangove added a comment -

          Here is an example of one of our coverage.xml reports. Produced via http://pypi.python.org/pypi/coverage.

          cangove added a comment - Here is an example of one of our coverage.xml reports. Produced via http://pypi.python.org/pypi/coverage .

          sogabe added a comment -

          attached coverage.xml which is generated by cobertura.

          sogabe added a comment - attached coverage.xml which is generated by cobertura.

          sogabe added a comment -

          You can see <sources>/<source> elements in my coverage.xml generated by cobertura.
          Cobertura plugin is looking for source code using a value of "sources/source". However your coverage.xml which is generated by coverage.py doesn't have them.

          I think coverage.py should fix it.

          sogabe added a comment - You can see <sources>/<source> elements in my coverage.xml generated by cobertura. Cobertura plugin is looking for source code using a value of "sources/source". However your coverage.xml which is generated by coverage.py doesn't have them. I think coverage.py should fix it.

          cangove added a comment -

          Thanks! That makes sense. So I can prep the proper report and possible fix for coverage, do the paths in <sources> need to be absolute or can they be relative to the coverage report?

          cangove added a comment - Thanks! That makes sense. So I can prep the proper report and possible fix for coverage, do the paths in <sources> need to be absolute or can they be relative to the coverage report?

          Jens Müller added a comment -

          Yes. Please provide proper documentation about what kind of paths the plugin expects ...

          (I just a thread to the jenkins Google Group about this as well.)

          Jens Müller added a comment - Yes. Please provide proper documentation about what kind of paths the plugin expects ... (I just a thread to the jenkins Google Group about this as well.)

          Jens Müller added a comment -

          And I should add that I use an absolute path for the <source> element and paths relative to it for the filename attribute, as in the attached example produced by Cobertura. And still I get the error message about missing source code.

          Jens Müller added a comment - And I should add that I use an absolute path for the <source> element and paths relative to it for the filename attribute, as in the attached example produced by Cobertura. And still I get the error message about missing source code.

          sogabe added a comment -

          See coverage_by_cobertura.xml.
          proper documentation? I don't know where it is.

          sogabe added a comment - See coverage_by_cobertura.xml. proper documentation? I don't know where it is.

          Tony Lampada added a comment -

          I found a workaround for this.
          Basically you need to make sure your build script leaves the coverage.xml file and the source code it links to relative to the workspace root.

          for example, here's a piece of my workspace structure:

          src
          -- estantemagica
          ---- core
          ------ *.py
          

          and my previous build script:

          cd src/estantemagica
          coverage erase
          coverage run --source='core' manage.py test --noinput core
          coverage xml
          

          and then I told Jenkins to publish the xml report from src/estantemagica/coverage.xml
          It doesn't find the files.

          Then I changed the build script to:

          cd src/estantemagica
          coverage erase
          coverage run --source='core' manage.py test --noinput core
          coverage xml
          cp -Rf * ../../
          

          and then I told Jenkins to publish the xml report from coverage.xml

          Then it works.

          Tony Lampada added a comment - I found a workaround for this. Basically you need to make sure your build script leaves the coverage.xml file and the source code it links to relative to the workspace root. for example, here's a piece of my workspace structure: src -- estantemagica ---- core ------ *.py and my previous build script: cd src/estantemagica coverage erase coverage run --source= 'core' manage.py test --noinput core coverage xml and then I told Jenkins to publish the xml report from src/estantemagica/coverage.xml It doesn't find the files. Then I changed the build script to: cd src/estantemagica coverage erase coverage run --source= 'core' manage.py test --noinput core coverage xml cp -Rf * ../../ and then I told Jenkins to publish the xml report from coverage.xml Then it works.

          Code changed in jenkins
          User: Karol Judek
          Path:
          src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java
          http://jenkins-ci.org/commit/cobertura-plugin/2ea94adb834c8dbd0c614b8eb93748c43e595150
          Log:
          [FIXED JENKINS-13889] Not able to find source code from subdirectories

          Code style fixes

          Fix line endings

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Karol Judek Path: src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java http://jenkins-ci.org/commit/cobertura-plugin/2ea94adb834c8dbd0c614b8eb93748c43e595150 Log: [FIXED JENKINS-13889] Not able to find source code from subdirectories Code style fixes Fix line endings

          Code changed in jenkins
          User: Arcadiy Ivanov
          Path:
          src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java
          http://jenkins-ci.org/commit/cobertura-plugin/a94a23f2570e27c7405290e57857ca9179156876
          Log:
          Merge pull request #43 from dzudek/master

          [FIXED JENKINS-13889] Not able to find source code from subdirectories

          Compare: https://github.com/jenkinsci/cobertura-plugin/compare/c27a7e591747...a94a23f2570e

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Arcadiy Ivanov Path: src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java http://jenkins-ci.org/commit/cobertura-plugin/a94a23f2570e27c7405290e57857ca9179156876 Log: Merge pull request #43 from dzudek/master [FIXED JENKINS-13889] Not able to find source code from subdirectories Compare: https://github.com/jenkinsci/cobertura-plugin/compare/c27a7e591747...a94a23f2570e

            stephenconnolly Stephen Connolly
            cangove cangove
            Votes:
            2 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: