Hudson "Source code is unavailable."
Asked Answered
D

5

11

I'm using Hudson to continuously build a Python project. Unit tests and code coverage work great, but this message appears when drilling into the Cobertura Coverage Report for my files that are not unit tests:

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.

The strange thing is that the source code for the unit tests are found and displayed. I tried to manually copy the source files for other .py files into ~/.hudson/jobs/<projectname>/cobertura (where the unit tests get copied), but it did not work.

Any suggestions?

Dramamine answered 18/2, 2010 at 1:16 Comment(0)
H
6

This is one hell of an ugly hack, but its the only thing that I could come up with to finally make it work... and after hours of Googling and hacking away trying to get results, this is the only thing I came up with.

coverage run manage.py test
coverage xml
sed 's/filename="/filename="my\/path\//g' coverage.xml > coverage2.xml

This is just relpacing the filename attribute of the class xml tags and adding the full path to the source files at the beginning. Just make sure that you update the Cobertura xml report pattern to be coverage2.xml (if that is where you're piping sed's output to).

It would be nice if the Cobertura plugin would allow you to enter the source path similar to how the Violations plugin does - unfortunately, as far as I'm aware, it doesn't.

I hope this helps!

Herminiahermione answered 26/5, 2010 at 19:9 Comment(1)
This does not work for me, with Jenkins. I tried an absolute path to my source code, and that it not work. I read at github.com/gotwarlost/istanbul/issues/50 that the path should be relative to the Jenkins workspace Cobdura directory. I tried that and relative to the workspace directory, but neither worked. Can anyone help?Crimpy
T
7

The Cobertura report file (which at this point is somewhere in $HUDSON/jobs/foo/workspace) needs to contain something like this at the beginning:

<sources>
  <source>/path/to/source</source>
  <source>/another/path</source>
</sources>

Does it have that? Do the paths point to the right place?

Another gotcha: when it says "most recent build", it actually means "most recent stable build" (i.e. the status ball is blue, as opposed to yellow).

Tempe answered 19/2, 2010 at 19:5 Comment(1)
It doesn't have that element. I manually added within the <coverage> element before the <packages> element, but no change. Is that the proper place? Is there a way to tell coverage to include the <sources> element when generating? Also, all builds are stable.Dramamine
H
6

This is one hell of an ugly hack, but its the only thing that I could come up with to finally make it work... and after hours of Googling and hacking away trying to get results, this is the only thing I came up with.

coverage run manage.py test
coverage xml
sed 's/filename="/filename="my\/path\//g' coverage.xml > coverage2.xml

This is just relpacing the filename attribute of the class xml tags and adding the full path to the source files at the beginning. Just make sure that you update the Cobertura xml report pattern to be coverage2.xml (if that is where you're piping sed's output to).

It would be nice if the Cobertura plugin would allow you to enter the source path similar to how the Violations plugin does - unfortunately, as far as I'm aware, it doesn't.

I hope this helps!

Herminiahermione answered 26/5, 2010 at 19:9 Comment(1)
This does not work for me, with Jenkins. I tried an absolute path to my source code, and that it not work. I read at github.com/gotwarlost/istanbul/issues/50 that the path should be relative to the Jenkins workspace Cobdura directory. I tried that and relative to the workspace directory, but neither worked. Can anyone help?Crimpy
N
6

For me the other two solutions did not work stand-alone, but a combination of both of them did:

...
coverage xml
sed 's/<!-- Generated by coverage.py: http:\/\/nedbatchelder.com\/code\/coverage -->/<sources><source>\/path\/to\/sourcefolder<\/source><\/sources>/g'

This just replaces a comment inserted by coverage.py with information about the source location.

Nez answered 13/8, 2010 at 12:29 Comment(1)
This saved my day and worked. Just make sure you don't have <sources/> tag there alreadyLevanter
O
1

Our solution was to alter our use of the cobertura-report ant task to include the full path to the source directory rather than the relative path.

 <cobertura-report format="xml" destdir="${coverage.dir}" srcdir="${basedir}/${src.dir}"/>

Basically, the relative pathing included in the cobertura xml report crosses up Hudson such that the Cobertura Plugin can't use it to find the source code. In our case, this was was symptomatic of the differences between how Hudson does its pathing for single module projects and multi-module projects.

Ocular answered 19/10, 2010 at 15:25 Comment(0)
A
-1

The "correct" way to fix this is by putting your project on the PYTHONPATH and running the tests/coverage from outside your repo. Since it looks like you're using Django, django-admin.py test --settings=myproject.settings will let you do this.

-- Originally posted by Pete in a comment, moved to answer.

Antibiosis answered 18/2, 2010 at 1:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.