• Stars
    star
    109
  • Rank 319,077 (Top 7 %)
  • Language
    Java
  • License
    MIT License
  • Created almost 14 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Jenkins cobertura plugin

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"
}

More Repositories

1

jenkins

Jenkins automation server
Java
21,381
star
2

docker

Docker official jenkins repo
Dockerfile
6,144
star
3

pipeline-examples

A collection of examples, tips and tricks and snippets of scripting for the Jenkins Pipeline plugin
Groovy
4,117
star
4

blueocean-plugin

Blue Ocean is a reboot of the Jenkins CI/CD User Experience
Java
2,877
star
5

configuration-as-code-plugin

Jenkins Configuration as Code Plugin
Java
2,521
star
6

kubernetes-plugin

Jenkins plugin to run dynamic agents in a Kubernetes/Docker environment
Java
2,206
star
7

job-dsl-plugin

A Groovy DSL for Jenkins Jobs - Sweeeeet!
Groovy
1,851
star
8

pipeline-plugin

Obsolete home for Pipeline plugins
1,711
star
9

JenkinsPipelineUnit

Framework for unit testing Jenkins pipelines
Groovy
1,426
star
10

gitlab-plugin

A Jenkins plugin for interfacing with GitLab
Java
1,418
star
11

jenkinsfile-runner

A command line tool to run Jenkinsfile as a function
Java
1,137
star
12

java-client-api

A Jenkins API client for Java
Java
888
star
13

jenkins-scripts

Scripts in Groovy, shell, Ruby, Python, whatever for managing/interacting with Jenkins
Groovy
880
star
14

build-monitor-plugin

Jenkins Build Monitor Plugin
Java
722
star
15

git-plugin

Git repository access for Jenkins jobs
Java
668
star
16

slack-plugin

A Jenkins plugin for posting notifications to a Slack channel
Java
664
star
17

pipeline-model-definition-plugin

Groovy
562
star
18

docker-workflow-plugin

Jenkins plugin which allows building, testing, and using Docker images from Jenkins Pipeline projects.
Java
500
star
19

ghprb-plugin

github pull requests builder plugin for Jenkins
Java
495
star
20

docker-plugin

Jenkins Cloud Plugin that uses Docker
Java
482
star
21

docker-inbound-agent

Docker image for a Jenkins agent which can connect to Jenkins using TCP or Websocket protocols
PowerShell
466
star
22

helm-charts

Jenkins helm charts
Mustache
448
star
23

pipeline-aws-plugin

Jenkins Pipeline Step Plugin for AWS
Java
423
star
24

jenkins.rb

Deprecated, see https://www.jenkins.io/jep/7
Ruby
394
star
25

generic-webhook-trigger-plugin

Can receive any HTTP request, extract any values from JSON or XML and trigger a job with those values available as variables. Works with GitHub, GitLab, Bitbucket, Jira and many more.
Java
377
star
26

email-ext-plugin

Jenkins Email Extension Plugin
Java
338
star
27

dingtalk-plugin

Dingtalk for jenkins
Java
336
star
28

warnings-ng-plugin

Jenkins Warnings Plugin - Next Generation
Java
323
star
29

plugin-installation-manager-tool

Plugin Manager CLI tool for Jenkins
Java
301
star
30

mesos-plugin

Mesos Cloud Jenkins Plugin
Java
290
star
31

github-plugin

Jenkins GitHub plugin
Java
286
star
32

ec2-plugin

Jenkins ec2 plugin
Java
285
star
33

ssh-steps-plugin

Jenkins pipeline steps which provides SSH facilities such as command execution or file transfer for continuous delivery.
Java
273
star
34

ansicolor-plugin

Jenkins ANSI Color Plugin
Java
252
star
35

pipeline-utility-steps-plugin

Small, miscellaneous, cross platform utility steps for Jenkins Pipeline jobs.
Java
237
star
36

docker-agent

Base Docker image for Jenkins Agents
PowerShell
231
star
37

ansible-plugin

Jenkins Ansible plugin
Java
223
star
38

workflow-cps-global-lib-plugin

Java
223
star
39

hashicorp-vault-plugin

Jenkins plugin to populate environment variables from secrets stored in HashiCorp's Vault.
Java
218
star
40

lib-file-leak-detector

Java agent that detects file handle leak
Java
217
star
41

bitbucket-branch-source-plugin

Bitbucket Branch Source Plugin
Java
213
star
42

gerrit-trigger-plugin

Java
212
star
43

remoting

Jenkins Remoting module
Java
212
star
44

workflow-aggregator-plugin

211
star
45

android-emulator-plugin

Android Emulator plugin for Jenkins
Java
207
star
46

docker-slaves-plugin

A Jenkins plugin to run builds inside Docker containers
Java
205
star
47

github-branch-source-plugin

GitHub Branch Source Plugin
Java
205
star
48

pipeline-stage-view-plugin

Visualizes Jenkins pipelines
JavaScript
204
star
49

jenkinsfile-runner-github-actions

Jenkins single-shot pipeline execution in a GitHub Action POC
Shell
199
star
50

amazon-ecs-plugin

Amazon EC2 Container Service Plugin for Jenkins
Java
193
star
51

trilead-ssh2

Patched trilead-ssh2 used in Jenkins
Java
193
star
52

cucumber-reports-plugin

Jenkins plugin to generate cucumber-jvm reports
Java
192
star
53

docker-build-publish-plugin

Java
192
star
54

performance-plugin

Performance Test Running and Reporting for Jenkins CI
Java
190
star
55

jira-plugin

Jenkins jira plugin
Java
169
star
56

gitea-plugin

This plugin provides the Jenkins integration for Gitea.
Java
168
star
57

embeddable-build-status-plugin

Embed build status of Jenkins jobs in web pages
Java
167
star
58

stashnotifier-plugin

A Jenkins Plugin to notify Atlassian Stash|Bitbucket of build results
Java
163
star
59

docker-ssh-agent

Docker image for Jenkins agents connected over SSH
PowerShell
162
star
60

workflow-cps-plugin

Java
160
star
61

http-request-plugin

This plugin does a request to an url with some parameters.
Java
154
star
62

kubernetes-pipeline-plugin

Kubernetes Pipeline is Jenkins plugin which extends Jenkins Pipeline to provide native support for using Kubernetes pods, secrets and volumes to perform builds
Java
154
star
63

stapler

Stapler web framework
Java
154
star
64

tfs-plugin

Jenkins tfs plugin
Java
145
star
65

jep

Jenkins Enhancement Proposals
Shell
144
star
66

kubernetes-cd-plugin

A Jenkins plugin to deploy to Kubernetes cluster
Java
140
star
67

jacoco-plugin

Jenkins JaCoCo Plugin
Java
139
star
68

qy-wechat-notification-plugin

企业微信Jenkins构建通知插件
Java
138
star
69

swarm-plugin

Jenkins swarm plugin
Java
135
star
70

git-client-plugin

Git client API for Jenkins plugins
Java
130
star
71

dependency-check-plugin

Jenkins plugin for OWASP Dependency-Check. Inspects project components for known vulnerabilities (e.g. CVEs).
Java
129
star
72

subversion-plugin

Jenkins subversion plugin
Java
127
star
73

git-parameter-plugin

Jenkins plugin for chosing Revision / Tag before build
Java
121
star
74

role-strategy-plugin

Jenkins Role-Strategy plugin
Java
120
star
75

groovy-sandbox

(Deprecated) Compile-time transformer to run Groovy code in a restrictive sandbox
Java
120
star
76

jenkins-design-language

Styles, assets, and React classes for Jenkins Design Language
TypeScript
116
star
77

acceptance-test-harness

Acceptance tests cases for Jenkins and its plugins based on selenium and docker.
Java
116
star
78

publish-over-ssh-plugin

Java
115
star
79

gitlab-branch-source-plugin

A Jenkins Plugin for GitLab Multibranch Pipeline jobs and Folder Organization
Java
115
star
80

scm-sync-configuration-plugin

Jenkins scm-sync-configuration plugin
Java
115
star
81

pipeline-as-yaml-plugin

Jenkins Pipeline As Yaml Plugin
Java
114
star
82

selenium-plugin

Jenkins selenium plugin
Java
112
star
83

docker-build-step-plugin

Java
111
star
84

jira-trigger-plugin

Triggers a build when a certain condition is matched in JIRA
Groovy
111
star
85

code-coverage-api-plugin

Deprecated Jenkins Code Coverage Plugin
Java
110
star
86

gradle-plugin

Jenkins gradle plugin
Java
109
star
87

credentials-plugin

Provides Jenkins with extension points to securely store, manage, and bind credentials data to other Jenkins plugins, builds, pipelines, etc.
Java
107
star
88

jira-steps-plugin

Jenkins pipeline steps for integration with JIRA.
Java
105
star
89

artifactory-plugin

Jenkins artifactory plugin
Java
104
star
90

build-flow-plugin

A plugin to manage job orchestration
Groovy
103
star
91

github-oauth-plugin

Jenkins authentication plugin using GitHub OAuth as the source.
Java
102
star
92

throttle-concurrent-builds-plugin

Java
101
star
93

pipeline-graph-view-plugin

Java
99
star
94

promoted-builds-plugin

Jenkins Promoted Builds Plugin
Java
96
star
95

ssh-slaves-plugin

SSH Build Agents Plugin for Jenkins
Java
96
star
96

github-pr-coverage-status-plugin

Nice test coverage icon for your pull requests just from Jenkins
Java
93
star
97

jenkins-test-harness

Unit test framework for Jenkins core and its plugins
Java
92
star
98

localization-zh-cn-plugin

Chinese Localization for Jenkins
HTML
91
star
99

opentelemetry-plugin

Monitor and observe Jenkins with OpenTelemetry.
Java
90
star
100

office-365-connector-plugin

Office 365 Connector plugin sends jobs status notifications to Microsoft Teams or Outlook
Java
89
star