GithubHelp home page GithubHelp logo

jenkinsci / cobertura-plugin Goto Github PK

View Code? Open in Web Editor NEW
109.0 118.0 132.0 718 KB

Jenkins cobertura plugin

Home Page: https://plugins.jenkins.io/cobertura/

License: MIT License

Java 98.07% CSS 0.92% XSLT 1.02%

cobertura-plugin's Introduction

Cobertura Plugin

Build Status

Jenkins Plugin

Jenkins Plugin Installs

This plugin allows you to capture code coverage report from Cobertura. Jenkins will generate the trend report of coverage.The Cobertura plugin can be downloaded here.

Version History

  • Version history can be found in the changelog
  • Tagged releases can be found here

⚠️ Older versions of this plugin may not be safe to use. Please review the following warnings before using an older version:|

The current thinking is to merge this plugin into more generic coverage plugin. Help appreciated.

Configuring the Cobertura Plugin

  1. Install the cobertura plugin (via Manage Jenkins -> Manage Plugins)
  2. Configure your project's build script to generate cobertura XML reports (See below for examples with Ant and Maven2)
  3. Enable the "Publish Cobertura Coverage Report" publisher
  4. Specify the directory where the coverage.xml report is generated.
  5. (Optional) Configure the coverage metric targets to reflect your goals.

Configuring build tools

Here are the configuration details for common build tools. Please feel free to update this with corrections or additions.

Maven 2

Quick configuration

You can either, enable "cobertura" analysis in your 'pom.xml' files or just tell Jenkins to run "cobertura" goal.

If you don't want to change your pom files, add the goal cobertura:cobertura to the Maven commands of your job in Jenkins:

pipeline {
    // ...
    stage('Code Coverage') {
        steps {
            sh 'mvn clean cobertura:cobertura'
        }
    }
}

Single Project

If you are using a single module configuration, add the following into your pom.xml. This will cause cobertura to be called each time you run "mvn package".

<project ...>
    ...
    <build>
        ...
        <plugins>
            ...
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <formats>
                        <format>xml</format>
                    </formats>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>cobertura</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            ...
        </plugins>
        ...
    </build>
    ...
</project>

Project hierarchies

If you are using a common parent for all Maven2 modules you can move the plugin configuration to the pluginManagement section of the common parent...

<project ...>
    ...
    <build>
        ...
        <pluginManagement>
            <plugins>
                ...
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>cobertura-maven-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <formats>
                            <format>xml</format>
                        </formats>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>cobertura</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                ...
            </plugins>
        </pluginManagement>
        ...
    </build>
    ...
</project>

And add the plugin group and artifact to the children:

<project ...>
    ...
    <build>
        ...
        <plugins>
            ...
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
            </plugin>
            ...
        </plugins>
        ...
    </build>
    ...
</project>

Execute cobertura only from Jenkins using profiles

It is highly recommend to reduce the workload of the developers machines by disabling the cobertura plugin and only using it from within Jenkins. The following excerpt from the parent shows how to do so:

<project ...>
    ...
    <profiles>
        <!-- Jenkins by default defines a property BUILD_NUMBER which is used to enable the profile. -->
        <profile>
            <id>jenkins</id>
            <activation>
                <property>
                    <name>env.BUILD_NUMBER</name>
                </property>
            </activation>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>cobertura-maven-plugin</artifactId>
                            <version>2.2</version>
                            <configuration>
                                <formats>
                                    <format>xml</format>
                                </formats>
                            </configuration>
                            <executions>
                                <execution>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>cobertura</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
    </profiles>
    ...
</project>

Now that your parent is only using the plugin management section if it is running from within Jenkins, you need the children poms adapted as well:

<project ...>
    ...
    <!-- If we are running in Jenkins use cobertura. -->
    <profiles>
        <profile>
            <id>jenkins</id>
            <activation>
                <property>
                    <name>env.BUILD_NUMBER</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>cobertura-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    ...
</project>

Ant

You must first tell Ant about the Cobertura Ant tasks using a taskdef statement. The best place to do this is near the top of your build.xml script, before any target statements.

<property name="cobertura.dir" value="C:/javastuff/cobertura" />

<path id="cobertura.classpath">
    <fileset dir="${cobertura.dir}">
        <include name="cobertura.jar" />
        <include name="lib/**/*.jar" />
    </fileset>
</path>

<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />

You'll need to instrument the classes that JUnit will be testing (not the test classes themselves) as such:

<cobertura-instrument todir="${instrumented.dir}">
    <ignore regex="org.apache.log4j.*" />
    <fileset dir="${classes.dir}">
        <include name="**/*.class" />
        <exclude name="**/*Test.class" />
    </fileset>
    <fileset dir="${guiclasses.dir}">
        <include name="**/*.class" />
        <exclude name="**/*Test.class" />
    </fileset>
    <fileset dir="${jars.dir}">
        <include name="my-simple-plugin.jar" />
    </fileset>
</cobertura-instrument>

Here's an example call to the JUnit ant task that has been modified to work with Cobertura.

<junit fork="yes" dir="${basedir}" failureProperty="test.failed">
    <!--
        Specify the name of the coverage data file to use.
        The value specified below is the default.
    -->
    <sysproperty key="net.sourceforge.cobertura.datafile"
        file="${basedir}/cobertura.ser" />

    <!--
        Note the classpath order: instrumented classes are before the
        original (uninstrumented) classes.  This is important.
    -->
    <classpath location="${instrumented.dir}" />
    <classpath location="${classes.dir}" />

    <!--
        The instrumented classes reference classes used by the
        Cobertura runtime, so Cobertura and its dependencies
        must be on your classpath.
    -->
    <classpath refid="cobertura.classpath" />

    <formatter type="xml" />
    <test name="${testcase}" todir="${reports.xml.dir}" if="testcase" />
    <batchtest todir="${reports.xml.dir}" unless="testcase">
        <fileset dir="${src.dir}">
            <include name="**/*Test.java" />
        </fileset>
    </batchtest>
</junit>

Finally, you need a task to generate the xml report, where:

  • destdir is where you want the report (coverage.xml) generated.
  • Your cobertura.ser is generated to your module root.
  • srcdir is where your *.java files are located. If you use multiple modules in one build process you need to include the module name, if you use the simple srcdir parameter. It is not required to include module name if you use fileset.
<cobertura-report format="xml" destdir="${coveragereport.dir}" srcdir="${src.dir}" />
<!-- You can use multiple source directories this way: -->
<cobertura-report format="xml" destdir="${coveragereport.dir}" >

    <fileset dir="${src.dir.java}">

        <include name="**/*.java" />

    </fileset>

    <fileset dir="${src.dir.main}">

        <include name="**/*.java" />

    </fileset>

</cobertura-report>

Gradle

Running Cobertura in gradle, copied from Piotr Gabryanczyk's post at http://piotrga.wordpress.com/2010/04/17/gradle-cobertura-integration-revisited/ and tweaked to work for gradle 1.5:

Create cobertura.gradle in the root of your project:

logger.info "Configuring Cobertura Plugin"

configurations{
  coberturaRuntime {extendsFrom testRuntime}
}

dependencies {
  coberturaRuntime 'net.sourceforge.cobertura:cobertura:1.9.4'
}

def serFile="${project.buildDir}/cobertura.ser"
def classes="${project.buildDir}/classes/main"
def classesCopy="${classes}-copy"


task cobertura(type: Test){
  dependencies {
    testRuntime 'net.sourceforge.cobertura:cobertura:1.9.4'
  }

  systemProperty "net.sourceforge.cobertura.datafile", serFile
}

cobertura.doFirst  {
  logger.quiet "Instrumenting classes for Cobertura"
  ant {
    delete(file:serFile, failonerror:false)
    delete(dir: classesCopy, failonerror:false)
    copy(todir: classesCopy) { fileset(dir: classes) }

    taskdef(resource:'tasks.properties', classpath: configurations.coberturaRuntime.asPath)
    'cobertura-instrument'(datafile: serFile) {
      fileset(dir: classes,
              includes:"**/*.class",
              excludes:"**/*Test.class")
    }
  }
}

cobertura.doLast{
  if (new File(classesCopy).exists()) {
    //create html cobertura report
    ant.'cobertura-report'(destdir:"${project.reportsDir}/cobertura",
            format:'html', srcdir:"src/main/java", datafile: serFile)
    //create xml cobertura report
     ant.'cobertura-report'(destdir:"${project.reportsDir}/cobertura",
            format:'xml', srcdir:"src/main/java", datafile: serFile)
    ant.delete(file: classes)
    ant.move(file: classesCopy, tofile: classes)
  }
}

Apply Cobertura.gradle in your build.gradle.

Either (if single project build):

apply plugin: 'java'
apply from: 'cobertura.gradle'

Or (if multi project build):

subprojects {
  apply plugin: 'java'
  apply from: "${parent.projectDir.canonicalPath}/cobertura.gradle"
}

cobertura-plugin's People

Contributors

alanharder avatar basil avatar beamerblvd avatar christ66 avatar cizezsy avatar cupcicm avatar daniel-beck avatar fjcapdevila avatar jbrejner avatar jeffpearce avatar jglick avatar jxpearce-godaddy avatar kohsuke avatar kunigaku avatar mbarrien avatar msabramo avatar ndeloof avatar offa avatar olamy avatar olivergondza avatar podarsmarty avatar rogerhu avatar romaerzhuk avatar seanf avatar sghill-rewrite avatar ssogabe avatar tamini avatar tobix avatar uhafner avatar wangmengqiang001 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cobertura-plugin's Issues

Warnings with ActionScript

Using the Cobertura plugin with an ActionScript project I'm getting a Warning:

ParseException in STDIN

Encountered " "{"  "{ "" at line 2
Was expecting:  ";"

Java 7 support

I was looking through the history of the updates and it explicitly says when the plugin was updated to work with JDK 5 and 6. I was wondering if the current plugin works with JDK 7. I know people are using it but it seems to have a good many problems. So does it actually work with Java 7, or are people just finding work-arounds for the problems they run into? Also what are the dependent versions of Jenkins, Maven, and Cobertura needed for the current plugin? (1.9.5)

Need more documentation

There is no README in the repo and there are no help buttons on the Jenkins UI.

This is a pretty complex plugin and would be awesome if there was some sort of documentation (either here or on the Jenkins UI, preferably the latter, maybe both).

confusing "Methods's new stability minimum"

The same code is run for twice, the first run update the "Methods's new stability minimum", i don't know where the 98.08 comes from, and this made the second run unstable

Overall coverage rate:
lines......: 94.5% (5601 of 5924 lines)
functions..: 95.0% (785 of 826 functions)
[Cobertura] Publishing Cobertura coverage report...
Publishing Cobertura coverage results...
Cobertura coverage report found.
Methods's new stability minimum is: 98.08

Overall coverage rate:
lines......: 94.5% (5601 of 5924 lines)
functions..: 95.0% (785 of 826 functions)
[Cobertura] Publishing Cobertura coverage report...
Publishing Cobertura coverage results...
Cobertura coverage report found.
Code coverage enforcement failed for the following metrics:
Methods's stability is 95.35 and set mininum stability is 98.08.
Lines's stability is 93.7 and set mininum stability is 94.4.

how to get the test results

I need to gain the test results and send them to my own DB

where could I get about that.

Actually, I don't find the code where run the test.

Thanks for your help

Source code is unavailable no matter what I do

I'm using #55 and everything seems to work fine, I see coverage results in jenkins with cool graphs, but I can't manage to get the sources to display in jenkins.

Source

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 build’s 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.
You do not have sufficient permissions to view this file.

image

There are a few related old issues:
#29
#38

There is this closed issue:
https://issues.jenkins-ci.org/browse/JENKINS-5235

My coverage.xml does have a valid path in sources:source tag. I was able to ls the sources from the path in the file.

        <sources>
                <source>/var/lib/jenkins/workspace/e-HTHYJUZDZMCL63QUXR6Q5QZPTK4AQEV3NNTYGGY2FQSB27WHP6ZA/MyAppName</source>
        </sources>

(only works with #55)

step([$class: 'CoberturaPublisher', coberturaReportFile: 'MyAppName/reports/coverage.xml'])

Results not published when jenkins job fails

Hi,
I'm using Cobertura-plugin v1.12 and Jenkins v2.92.
In Jenkins job in section Publish Cobertura Coverage Report have:
unselected option: Consider only stable builds
and selected Fail unhealthy builds

When Jenkins job fail because code didn't meet code coverage limits then Cobertura Coverage Report is not published.

[Cobertura] Publishing Cobertura coverage report...
[Cobertura] Publishing Cobertura coverage results...
[Cobertura] Cobertura coverage report found.
[Cobertura] Unhealthy for the following metrics:
    Methods's health is 84.24 and set minimum health is 86.24.
    Lines's health is 89.49 and set minimum health is 90.49.
    Conditionals's health is 53.7 and set minimum health is 54.7.
ERROR: Step ‘Publish Cobertura Coverage Report’ failed: [Cobertura] Failing build because it is unhealthy.
Recording test results
Finished: FAILURE

Is autoUpdateHealth, autoUpdateStability supported with Jenkins pipeline?

I noticed that the syntax generator for the plugin that when I check off autoUpdateStability and autoUpdateHealth the options are left out of my final syntax.

When false:

step([$class: 'CoberturaPublisher', autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: 'coverage.xml', maxNumberOfBuilds: 0, onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false])

When true:

step([$class: 'CoberturaPublisher', autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: 'coverage.xml', maxNumberOfBuilds: 0, onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false])

Which made me question if this was supported in pipeline? I've had some trouble validating regressions.

Error when publishing report to jenkins

After the coverage report is generated, it is trying to publish the report but it is failing. Not sure if this is a conflict with other plugin and related to the classloader.

java.lang.ClassCastException: com.ctc.wstx.stax.WstxInputFactory cannot be cast to javax.xml.stream.XMLInputFactory
at javax.xml.stream.XMLInputFactory.newInstance(XMLInputFactory.java:153)
at hudson.plugins.cobertura.CoberturaPublisher$ParseReportCallable.invoke(CoberturaPublisher.java:532)
at hudson.plugins.cobertura.CoberturaPublisher$ParseReportCallable.invoke(CoberturaPublisher.java:519)
at hudson.FilePath.act(FilePath.java:990)
at hudson.FilePath.act(FilePath.java:968)
at hudson.plugins.cobertura.CoberturaPublisher.perform(CoberturaPublisher.java:337)
at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:782)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:723)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.post2(MavenModuleSetBuild.java:1037)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:668)
at hudson.model.Run.execute(Run.java:1763)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:529)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410)

Branch coverage reported incorrectly

branch-rate output in the coverage xml file is 0.1721, yet the report states that the "Conditionals's health is 13.12" (and then fails the build because the unhealthy threshold is 15.0). Upon closer inspection of the branch coverage, many files are slightly off (reports that 2 branches were missed even though they weren't), and some files are way off (reports that there was a maximum of 2 branches in the file, even though there is actually 39).

This issue occurs using versions 1.12 and 1.10 of the plugin.

Something to note is that coverage reporting is currently working for a different project, and the main differences are that the project which is failing was bootstrapped using create-react-app and is using version 20.0.4 of jest. Whereas the project where coverage reporting is working was not bootstrapped (created from scratch), and is using version 21.1.0 of jest. Note that both projects are using the same version of istanbul-reports (1.1.2) – in case that matters.

I thought initially that the coverage wasn't being collected properly, however the html and xml files generated seem to have the correct coverage values in them, it's only the branch values reported by the plugin which are incorrect.

To summarise the problem:

  • Correct coverage values are output to the coverage xml file
  • Incorrect branch/conditional coverage values are reported by the plugin

Are you aware of any version compatibility issues that could be occurring here such that the xml file is read incorrectly?

Impossible to see Coverage Breakdown for a package named "api"

If I visit the "Cobertura Coverage Report" page for a job and then go to "Coverage Breakdown by Package", if that package is named "api" the link takes me to Jenkins' api page, not the breakdown for that package. I guess one solution is to use /<packagename>-report for the URL instead of /<packagename>.

Help running locally

Team, great job on the plugin . Works great on jenkins.

Question. Would you guys consider developing a standalone viewer (without jenkins). I have the test framework (jasmine/jscover) which generates this cobertura xml file. I would like to view this in report format locally (without using jenkins) to see how much code is covered, before i submit my tests etc.. Dont need all the bells and whistles , just something which shows graphically in html/css which lines are covered and which is not.

If you guys have no time, can someone point me which classes i can look at to try and implement something like this.

Thanks.

Results not published when jenkins job fails

The Consider only stable builds option says - *Include only stable builds, i.e. exclude unstable and failed ones. *

But when the job actually fails, Cobertura prints "Skipping Cobertura coverage report as build was not UNSTABLE or better ..." and quits.

No coverage report generated when project directory is set

I'm trying to get a coverage report with the cobertura plugin, but the graph and data shows no entries. When I browse my workspace to the coverage.xml I can see content in this file. When I run my scripts to generate the coverage.xml manually, the report is filled too.

In my project setup I specify a different directory as workspace. I suspect that this is the cause of my problem. I tried to find a place in the sourcecode where this happens, but I'm not yet sure.

Support more than one report per job

It would be great to be able to generate more than one coverage report and time plot. We do that now by teiggering a separate job that uses the same workspace as the first job to generate “focused” coverage report for certain areas that we are working on improving code coverage in

How can I set the Source Encoding

Hello - We are using Jenkins 1.642.1 and we generate Cobertura reports for both build/deploy jobs and functional test jobs. The generated report includes a link to the source file which included red/green color coding to indicate line hits. This file includes non-ASCII characters so garbage chars are rendered in the html view of this file.
When I check the configuration of the build job (which is generated by groovy scripts) the Source Encoding setting for the 'Publish Cobertura Coverage Report' indicates "ASCII" as the setting. I need it to be UTF-8. I can choose this manually, but we don't mess with our builds manually. Everything is generated in CI style - using programming.
In this case, I see the line in the groovy script and it calls 'cobertura '. There doesn't seem to be any room for additional arguments including that for the source encoding. Can someone point me the right direction to set this value programmatically?

Thanks,
Rob

Source code not getting painted

I'm generating Cobertura-style XML from another tool (a patched version of JCov, actually), and everything seems to work fine, except that the Jenkins plugin doesn't seem to generate painted source code reports at all.

Some cursory source-diving revealed a possible problem in CoberturaCoverageParser, where NumberFormatExceptions are quietly ignored, resulting in the lines not being recorded as painted. I'm pasting a small subset of the XML I'm generating here, on the off chance that it's something wrong with my XML (I can't seem to attach it as a file):
<coverage line-rate="0.8223350253807107" branch-rate="0.25"> <sources> <source>/home/eric/src/krypton/src/main/java/</source> </sources> <packages> <packages name="net.metricspace.crypto.ciphers.stream.salsa" line-rate="0.8636363636363636" branch-rate="0.25" complexity="1.0"> <classes> <class name="ChaCha20CipherSpi" filename="net/metricspace/crypto/ciphers/stream/salsa/ChaCha20CipherSpi.java" line-rate="0.7272727272727273" branch-rate="0.0"> <methods> <method name="&lt;init&gt;" signature="()V" line-rate="1.0" branch-rate="0.0"> <lines> <line number="76" hits="81804" branch="false"/> </lines> </method> <method name="engineGetParameters" signature="()Ljava/security/AlgorithmParameters;" line-rate="0.4" branch-rate="0.0"> <lines> <line number="134" hits="0" branch="false"/> <line number="136" hits="0" branch="false"/> <line number="138" hits="0" branch="false"/> <line number="142" hits="163593" branch="false"/> <line number="131" hits="163593" branch="false"/> </lines> </method> <method name="rounds" signature="()V" line-rate="1.0" branch-rate="0.0"> <lines> <line number="150" hits="245397" branch="false"/> </lines> </method> </methods> <lines> </lines> </class> </class> </classes> </packages> </packages> </coverage>

Cobertura missing stax2-api failing to parse coverage.xml

Installed cobertura from the jenkins plugins page. Jenkins is 1.625.3

I don't know the java side that well, but I can run any kind of testing or anything else. I've tried dropping stax2-api.jar directly into the WEB-INF/lib directory of the cobertura plugin but that didn't seem to fix anything. Next step I'll take is uninstall and reinstall.

Running gcov: 'gcov /var/lib/jenkins/jobs/openvswitch-build/workspace/lib/dirs.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /var/lib/jenkins/jobs/openvswitch-build/workspace/lib' in '/var/lib/jenkins/jobs/openvswitch-build/workspace/lib'
Parsing coverage data for file /var/lib/jenkins/jobs/openvswitch-build/workspace/lib/dirs.c.in

Parsing coverage data for file /var/lib/jenkins/jobs/openvswitch-build/workspace/include/openvswitch/thread.h
Gathered coveraged data for 302 files
[Cobertura] Publishing Cobertura coverage report...
ERROR: Step ‘Publish Cobertura Coverage Report’ aborted due to exception:
java.lang.NoClassDefFoundError: org/codehaus/stax2/XMLInputFactory2
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:421)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:383)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:370)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at javax.xml.stream.FactoryFinder$1.run(FactoryFinder.java:353)
at java.security.AccessController.doPrivileged(Native Method)
at javax.xml.stream.FactoryFinder.findServiceProvider(FactoryFinder.java:341)
at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:313)
at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:227)
at javax.xml.stream.XMLInputFactory.newInstance(XMLInputFactory.java:154)
at hudson.plugins.cobertura.CoberturaPublisher$ParseReportCallable.invoke(CoberturaPublisher.java:538)
at hudson.plugins.cobertura.CoberturaPublisher$ParseReportCallable.invoke(CoberturaPublisher.java:525)
at hudson.FilePath.act(FilePath.java:991)
at hudson.FilePath.act(FilePath.java:969)
at hudson.plugins.cobertura.CoberturaPublisher.perform(CoberturaPublisher.java:343)
at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:785)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:726)
at hudson.model.Build$BuildExecution.post2(Build.java:185)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:671)
at hudson.model.Run.execute(Run.java:1766)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:408)
Caused by: java.lang.ClassNotFoundException: org.codehaus.stax2.XMLInputFactory2
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:430)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:383)
... 36 more
Finished: FAILURE

Source coverage report for several recent builds

I'd try to take a look at source coverage report for some old build, but get this message:

2014-05-26 15-12-51 google

Is there any way to setup cobertura-plugin to keep source coverage reports for several recent builds?

Source code is unavailable unless you have admin rights

When using version 1.12.1 of the plug-in the source code can only be seen when you have admin rights on jenkins. If that's not the case, you get

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 build’s 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. 
  • You do not have sufficient permissions to view this file. -

Is there a solution for that ?

JENKINS-23183: Add precision option for the "Stability auto update"/"Health auto update" options

Now we get 50% of the builds failed even when a single line of code is modified, just because of the rounding errors.

The situation is even worse because exporting status via cc.xml files (CCTray) supports only success and failed, and the unstable is mapped as a failure without any way of changing this. So we see lots of "red" builds just because the code coverage went from 99.99% to 99.98%. Clearly the threshold for measuring a decrease should be a percent, not a "rounding error".

Based on original bug raise at https://issues.jenkins-ci.org/browse/JENKINS-23183

Double escaping by XML entities

I have coverage.xml generated from C++ project so the problem is much more visible then for java.

In coverage.xml, I have this method definition

<method branch-rate="1.0" line-rate="1.0" name="MyClass&lt;int&gt;::MyMethod(OtherClass&amp;)" signature="">

I would like to see MyClass<int>::MyMethod(OtherClass&) in all places but it is not true. When I reach to page "Coverage Breakdown by Method", list of methods contains XML entities instead of real characters and method is displayed as MyClass&lt;int&gt;::MyMethod(OtherClass&amp;). After clicking some method, I can see page with wrong title still containing XML entities but "Method Coverage summary" contains correct name.

Jenkins: 2.128
Cobertura-plugin: 1.12.1
Java: OpenJDK 1.8.0_171

When coverage goes down threshold is updated and the build is not marked as unstable

Using the snippet generator I've added the following step to my Jenkinsfile:

cobertura coberturaReportFile: 'coverage.xml', conditionalCoverageTargets: '80, 0, 0', failUnhealthy: true, failUnstable: true, lineCoverageTargets: '80, 0, 0', maxNumberOfBuilds: 0, methodCoverageTargets: '80, 0, 0', onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false

This should set the initial threshold to 80% for lines, methods and conditionals and auto-update the minimum when the build is successful (as autoUpdateHealth and autoUpdateStability are true by default). But when coverage goes down the threshold is updated and the build is not marked as unstable:

The pipeline steps reports the update of the thresholds:

    Methods's new health minimum is: 78.84
    Lines's new health minimum is: 82.19
    Conditionals's new health minimum is: 72.23
    Methods's new stability minimum is: 78.84
    Lines's new stability minimum is: 82.19
    Conditionals's new stability minimum is: 72.23

In other non-pipeline jobs using the cobertura-plugin, when the coverage is bellow the minimum the coverage does not get updated and the build is marked as unstable.

Environment

  • Jenkins v.2.73.3
  • Cobertura plugin v1.12
  • Pipeline plugin v2.5
  • Pipeline: API plugin v2.23.1

java.lang.NoSuchMethodError when trying to post to phabricator

We run our test suite using jenkins, and recently we started seeing this error in our Post to Phabricator post-build step

ERROR: Step ‘Post to Phabricator’ aborted due to exception: 
java.lang.NoSuchMethodError: hudson.plugins.cobertura.targets.CoverageResult.setOwner(Lhudson/model/AbstractBuild;)V
	at com.uber.jenkins.phabricator.coverage.CoberturaCoverageProvider.computeCoverage(CoberturaCoverageProvider.java:131)
	at com.uber.jenkins.phabricator.coverage.CoberturaCoverageProvider.hasCoverage(CoberturaCoverageProvider.java:61)
	at com.uber.jenkins.phabricator.PhabricatorNotifier.getCoverageProvider(PhabricatorNotifier.java:252)
	at com.uber.jenkins.phabricator.PhabricatorNotifier.perform(PhabricatorNotifier.java:98)
	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:730)
	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:676)
	at hudson.model.Build$BuildExecution.post2(Build.java:186)
	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:621)
	at hudson.model.Run.execute(Run.java:1760)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:415)
Finished: FAILURE

This error still persists even after unchecking the "Enable Uberalls" option in the builds "Configure" tab. We are using plugin version 1.10, and for some reason we can't uninstall it (the option is greyed out)

What do we need to do to rid us of this Runtime Error?

Change report column names?

Hi, I wanted to know if it's possible to change, in Jenkins, when using Cobertura's Project Coverage Summary to change the column names?

For example, how can I change the following to a custom name:
Image

rounding issues

It seems like coverage plugin rounds coverage before saving, but it seems to use actual value when checking whether build should fail or not. This causes issues when 'ratcheting' is used and coverage is meant to slowly go up. What happens is that once coverage reaches x.05, builds start to fail because plugin is
then requiring x.1 coverage.
This probably only occurs when auto update is enabled.

Jenkins version: 1.583
Cobertura plugin version: 1.9.5

Add support for multiple coverage file

In my project, in the same job we build .net and Angular Project. So we have two cobertura report.
Please add some params to speciy the directory for cobertura report and for the cobertura report name (in the sidebar).
Maybe there are some others impacts to develop

Example of PublisherTarget on pipeline

Hi,

I used the new release of the plugin with this step

step([$class: 'CoberturaPublisher', coberturaReportFile: 'coverage.xml', onlyStable: false])

How can I set healthy/unhealthy/unstable target using pipeline syntax ?

Thanks in advance,

source codes are not available when build fails

This could be either a bug or a feature: the current behavior is that annotated source codes are only available if a build succeeds, as indicated by this line:

return owner == owner.getParent().getLastSuccessfulBuild() && getSourceFile().exists();

In our use case, we fail a build when test coverage is unstable or unhealthy. This means that the source codes are not available when they are most needed: when coverage drops.

It would be great if there is an option to always make source codes available regardless of build result.

Links in dashboard are wrong

Sine the update of jenkins to 1.572 on a dashboard with Code Coverages(Cobertura) portlet the links to the job contain twice the part /view/viewname.

So all links end up in a 404

Cobertura.sourceforge missing coverage-03.dtd

We are noticing an issue with our CI server. Is the plugin changing or is this an issue with the file not existing out on sourceforge? We are getting the following stacktrace:

Caused by: java.io.FileNotFoundException: http://cobertura.sourceforge.net/xml/coverage-03.dtd
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1401)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:655)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1293)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:1260)
    at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:260)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1169)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1065)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:978)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:625)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:819)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:748)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1208)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:525)
    at org.dom4j.io.SAXReader.read(SAXReader.java:465)
    ... 23 more

XML method name formatting

If an XML file contains methods with less-than, greater-than, and ampersand symbols in the name, then the HTML report generated is displaying &lt; , &gt; , &amp; for the method name instead of the actual symbol. This seems to be due to the xmlTransform function being executed on the method name which converts the & at the start of the entity into &amp; which makes the rest of the entity invalid. If you click down to the "Method Coverage summary" then it ends up displaying correctly because that doesn't run the xmlTransform function.

It seems like the XMLHandler should normalize the element's attribute to convert the entities into the regular characters and then have an htmlTransform to convert the characters back into HTML entities later.

You can see this by loading the the test coverage.xml file in the test resources directory and seeing the &lt;init&gt; method.

Source code is unavailable (Cobertura plugin 1.10)

I'm producing coverage report by coverage.py and use "Publish cobertura report".
I do have "Cobertura Coverage Report" , but couldn't not see Python sources.
Can please someone point to to the document or example or proper coverage.xml file?
I reviewed coverage.xml, and filenames seem be right - "/opt/mydir/mypackage/vitaly.py".
In the same time into "Coverage Breakdown by File" section of report I see this path without leading slash, i.e. "opt/mydir/mypackage/vitaly.py".

Seems to be different from #102 - I do have admin right.

TIA,
Vitaly

java.lang.SecurityException: agent may not write

Hi,
I'm using the cobertura plugin in a job that runs on a Jenkins node. The jobs fails because

[Cobertura] Publishing Cobertura coverage report...
Publishing Cobertura coverage results...
Cobertura coverage report found.
ERROR: Build step failed with exception
java.lang.SecurityException: agent may not write 

I set up the Slave to master to allow all < BUILDDIR >/.* as described here but it still fails
https://wiki.jenkins-ci.org/display/JENKINS/Slave+To+Master+Access+Control

How can I set the correct rights for the plugin?

cheers

Integration with the CI Game plugin

Hi i'd like to integrate this plugin with the CI Game plugin, for this plugin to add a few rules to add points when coverage's improved. Any idea or insight on where to begin ?

Regards,

Olivier.

Coverage measure for metric 'lines_to_cover' should not be saved directly by a Sensor

On a Jenkins task configured to use Cobertura to report Code Coverage both to Jenkins and SonarQube we are getting the following warnings in the console log:

[WARNING] Coverage measure for metric 'lines_to_cover' should not be saved directly by a Sensor. Plugin should be updated to use SensorContext::newCoverage instead.
[WARNING] Coverage measure for metric 'uncovered_lines' should not be saved directly by a Sensor. Plugin should be updated to use SensorContext::newCoverage instead.
[WARNING] Coverage measure for metric 'coverage_line_hits_data' should not be saved directly by a Sensor. Plugin should be updated to use SensorContext::newCoverage instead.
[WARNING] Coverage measure for metric 'conditions_to_cover' should not be saved directly by a Sensor. Plugin should be updated to use SensorContext::newCoverage instead.
[WARNING] Coverage measure for metric 'uncovered_conditions' should not be saved directly by a Sensor. Plugin should be updated to use SensorContext::newCoverage instead.
[WARNING] Coverage measure for metric 'conditions_by_line' should not be saved directly by a Sensor. Plugin should be updated to use SensorContext::newCoverage instead.
[WARNING] Coverage measure for metric 'covered_conditions_by_line' should not be saved directly by a Sensor. Plugin should be updated to use SensorContext::newCoverage instead.

What additional info should I provide? What could wrong?

  • Jenkins: ver 2.82
  • SonarQube: Version 6.5 (build 27846)
  • Cobertura Plugin in Jenkins: 1.19
  • Cobertura Plugin in SonarQube: 1.9.1
  • cobertura-maven-plugin:2.7

Issue in StackExchange also.

Can't find coverage.xml, which exists and matches search pattern

Hi, the Cobertura plugin seems to have a problem finding the coverage documents. When configured to fail when no coverage files are found, the job does fail.

The files are there. Log message is:

[Cobertura] No coverage results were found using the pattern '**/target/site/cobertura/coverage.xml​' relative to '/home/[user]/jenkins_server_home/jenkins/jobs/Measure_code_quality/workspace'

Listing such a directory:

$ ll /home/[user]/jenkins_server_home/jenkins/jobs/Measure_code_quality/workspace/[appName]/target/site/cobertura
total 304
-rw-r--r-- 1 jenkins jenkins 308049 Jan 15 14:07 coverage.xml

Browsing the job's workspace, I can see the file "[appName]/target/site/cobertura/coverage.xml", which is non-empty and looks well-formed. Coverage rates are non-zero.

I have verfied that these files are actively being produced by wiping out the job's workspace and rebuilding.

Can you offer any insight into this?

How to use cobertura with parallel build ?

I'm trying to understand how to use cobertura when we are compiling and testing on multiple configuration. We have create a build to run on multiple axis (debian version, python version, cherrypy version, etc.) Each of them are running tests and generating a coverage.xml report.

How should I use cobertura in this situation ?

Here the Jenkins file: https://github.com/ikus060/rdiffweb/blob/develop/Jenkinsfile

Right now, I've try to publish the coverage report for each build. But it adds an entry on the Job. Like this
image

Links from project page.

They lead to cobertura/ which gets redirected to {lastbuildnumber}/cobertura/ which is usually ok by in some cases, when project name contains URI-encode symbols (it's sometimes important for multibranch projects), they get decoded and it breaks everything. Yes, I know that relying on URI-encoding is somewhat fragile idea, but that's how things are.

Can you please change those links to lastCompletedBuild/cobertura/ which is the same thing but doesn't require any redirects? If nothing else, without that additional redirect it will be a bit faster for users.

Cobertura publishing fails with java.lang.SecurityException: slave may not mkdirs when the job runs in slave node

Jenkins master is now more strict about what commands its slaves can send to the master. Unfortunately, this prevents some plugins from functioning correctly, as those plugins do not specify which commands are open for slaves to execute and which ones are not
For more reference
https://wiki.jenkins.io/display/JENKINS/Slave+To+Master+Access+Control

Here I feel fix should be mainly related to implementing the SECURITY-144-compat module in the plugin code.
However we have passing scenario also for the jobs running in slaves.
(Are the commands being used in this case are different ? )

Jenkins is unable to find and display the source markup when a build fails due to a test failure

If a build is configured to fail if a test point fails (using the "Failed tests mark build as failure" option under TAP results), the coverage report does not find the source files and encode them based on coverage results. The coverage results, however, are reported correctly in the form of numbers.

The issue seems to be in the following piece of code in CoverageResult.java -

public boolean isSourceFileAvailable() {
if (hasPermission()) {
return owner == owner.getParent().getLastSuccessfulBuild() && getSourceFile().exists();
}
return false;
}

In my opinion, as a user I would expect the source code encoding to be reported as well if the coverage results are computed (and a .XML file is created in the workspace). So should the check be limited to something as simple as -

if (hasPermission()) {
return owner == getSourceFile().exists();
}
return false;

combine .cov files(created by different jobs) for the same module and display them as one package

Windows 10
Jenkins 2.109
Cobertura 1.12

I have an issue with combining .cov from different Jenkins jobs.

Job1 (PC1) : Coverage created for module A.dll through UnitTestForA.exe Gives => UTCoverage.cov
Job2 (PC2) : Coverage created for module A.dll through FunctionalTestForA.exe Gives => FuncCoverage.cov

I fuse both coverages, UTCoverage.cov and FuncCoverage.cov, and output them as a Cobertura report.
The issue is that when I view the report it has a separate package for each job.

Is there a way that the module A.dll that was built by different jobs be reported as one package?

Note: When I change job2 to have the same name as job1 the report combines the modules correctly

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.