How to change value of name column in cobertura report
Asked Answered
J

4

8

I am using cobertura plugin in jenkins for code coverage. I want to change value of name column in Project Coverage summary on a per-report basis. enter image description here

Is there any way to change this. I want to give my project name over there.

Janeenjanek answered 21/3, 2014 at 10:9 Comment(1)
Can you say if you're using Maven, Ant or command line with plugin? It's hard to know what's going on with so little detail.Bipartisan
C
4

Here is a fork of the plugin that does what you are asking (project name instead of "cobertura coverage report").

https://github.com/andytompkins/cobertura-plugin

cobertura plugin with project name

Right now it just uses the project name. I suppose this could become a configurable item? I'll be glad to work on it more if something else is needed, and could probably even package the changes up in a way that upstream will take them.

The relevant code that was changed was in CoverageResult.java. Added a method:

public String getJobName() {
    AbstractProject job = owner.getProject();
    return job.getName();
}

And in the index.jelly changed the reference from it.name to it.getJobName().

<td>${it.getJobName()}</td>

It will be a bit harder to make it on a per-report basis. The report itself does not have a name or title field - and this plugin does not control the format, it just reads it.

I too am using this with a javascript project that uses karma and karma-coverage. Currently running the forked plugin in production jenkins.

EDIT: In the branch use-filename-for-reportname in my repo you will find a version of the plugin that will use the coverage file's name as the report name.

report name from file

Crackdown answered 6/5, 2014 at 20:55 Comment(7)
maybe it could base it off the filename?Standardbearer
That could work, on my system the generated file name is kinda ugly: coverage-PhantomJS 1.9.7 (Linux)-20140506_162233.jsonCrackdown
Of course it's not immediately obvious how to get the report filename at this spot in the code. Gonna take me a little bit to figure this out :)Crackdown
You should be able to control the output filename from Karma though.Standardbearer
Are you sure? The docs seemed to indicate that only worked with the text output: If you set type to text or text-summary, you may set the file option, like this.Crackdown
I guess it doesn't matter, there's any number of ways to change the filename. We only ever generate 1 report per "build" in jenkins. I assume others might be generating multiples in a given build?Crackdown
Ok, there ya go, uses the file name. Ideally I guess you could pick in the configuration section to use the project name, or file name, or static text.Crackdown
G
2

I suggest going to the plugin page, contacting one of the maintainers:
Stephen Connolly (id: stephenconnolly)
Manuel Carrasco Monino (id: manuel_carrasco)
Seiji Sogabe (id: ssogabe)

And asking them how you can do it.
Once you have the solution, share it here, because others (like me) might also want this capability...

I hope this helps.

Genitor answered 30/4, 2014 at 7:31 Comment(0)
G
2

You can go to the plugin Github page, and clone a copy of the source code for yourself.

A quick search reveals that the line you want to change is probably located in this file:
src/main/resources/hudson/plugins/cobertura/Messages.properties

CoberturaCoverageParser.name=Cobertura Coverage Report

Change that line to what you want. Save and rebuild the plugin. There is a big tutorial on how to build Jenkins plugins here.

Goingover answered 30/4, 2014 at 14:49 Comment(5)
Well I checked the source code as well and turn out that it isn't the only file that has the String "Cobertura Coverage Report", found at least 3.Bipartisan
That's why I said probably. I saw the 3 matches as well, but my bet is on that particular line. If that doesn't work, you can always try the other two.Goingover
Yeah you're right but still it's hard to pull that off and try it to change one string, and enhancement in Cobertura which gives the user the possibility to change that in config is more the answer he's looking for but that doesn't seem to be possible.Bipartisan
This is not an ideal way to accomplish this. I'm hoping for a way to do it based on the input file, not change it globally for all reports.Standardbearer
Then the people you should be asking are the plugin maintainers, as @Eldad suggestedGoingover
B
0

Well I only used Cobertura once in Maven and there you can choose between a xml and html output, which is created in the outputDirectory you define in your project's pom.xml file.

Supposing that the logic is the same you could go to the generated xml or html files and simply search for the string "Cobertura Coverage Report" and changing it there.

This will work if the objective of changing it is to send to someone (for example: a report to your boss).

As far as I see it's not possible, for now, to change some config and have a definite solution.

What I'd suggest is, to open a issue at the plugin page or even at their OpenSource Repository at GitHub and propose the enhancement or even contribute yourself.

If that doesn't make them move I'd suggest trying to contact the maintainers at the plugin page.

Edit (30-04-2014):

The solution you're looking for is not available, Cobertura doesn't support it. The Cobertura plugin will show always that same report structure where the overall report summary will always have the value "cobertura coverage report", the Emma coverage plugin who is very similar has on that same spot the string value "all packages", unless you edit the source code or ask for an enhancement, sorry.

In case you opt to change the source code, it's indeed the value suggested by Slav:

src/main/resources/hudson/plugins/cobertura/Messages.properties

CoberturaCoverageParser.name=Cobertura Coverage Report

But in this case you'd have to create and install a new plugin for each project you'd have.

So at the bottom-line I wouldn't go in that direction. On the other hand, what I'd suggest is using Cobertura or Karma (in Daniel Schaffer's case) to generate html instead. This one can easily be altered with basic html and css skills to have your desired look and feel.

Bipartisan answered 30/4, 2014 at 16:32 Comment(8)
I tried this, and that string does not appear in the XML file that is generated.Standardbearer
But the report you refer to is the one that appears in the Jenkins plugin itself? Or in on of the outputs itself? Because if it's in the output it should be editable, if otherwise it would only be possible by changing the source code of the plugin and compile your custom version of it... But that looks like a bad solution to me...Bipartisan
My report is generated by Karma's coverage plugin, but I couldn't find any options to name the report, and like I said, I don't even see that string in the xml it generates.Standardbearer
Does it generate anything else with it? Because if it's with Karma it's something else.Bipartisan
It can generate other report formats, but as far as I know, the XML file is the only thing that the Jenkins cobertura plugin picks upStandardbearer
Let me see if I get this straight? You're using karma to generate a Cobertura coverage report and then you open it with the Cobertura report in Jenkins? If this is the problem I think I know what's wrong... Be back at you in a second.Bipartisan
Yes, that's what I'm doing.Standardbearer
Sorry but looks like it's the only option... :-/Bipartisan

© 2022 - 2024 — McMap. All rights reserved.