LogoLogo
diffblue.comFree trial
  • Discover Diffblue Cover
  • Get Started
    • What is Diffblue Cover?
    • Get started
      • Free trial
      • Get started - Cover Plugin
      • Get started - Cover CLI
      • Get started - Cover Pipeline
      • Get started - Cover Reports
    • Specs & Reqs
    • Reference Deployments
    • Licensing
      • Online license activation
      • Offline license activation
      • Diffblue License Manager
    • Update Cover
    • FAQs
    • Diffblue Learning
      • Get started
        • Just the basics
        • Free trial
        • Cover Plugin (IDE)
        • Cover CLI (Command Line)
      • Developer
        • Unit tests (IDE)
        • Unit tests (CLI)
        • Test coverage
      • DevOps
        • GitHub
        • GitLab
        • Other CI
      • Administrator
        • Admin - IntelliJ
        • Admin - CLI
        • Admin - Reports
      • Test coverage
        • Developer
        • Senior developer
        • Cover Reports Administrator
  • EVALUATION & ONBOARDING
    • Proof of Value
    • Jumpstart
      • Prerequisites for onboarding
      • Phase 1: Up and running
        • Module 1: Create your Cover unit test baseline
        • Module 2: Cover Pipeline CI integration
      • Phase 2: Developer productivity
        • Module 3: Getting started using Cover
        • Module 4: Introduction to Cover Reports
      • Phase 3: Advanced topics
        • Module 5: Speed up your test execution
        • Module 6: Getting more from Cover
  • Features
    • Cover Plugin
      • Writing tests
        • Gutter icons
        • Menu options
        • Run configurations
        • Cover Plugin tool window
        • Test Review
        • Test examples
        • Creating partial tests
        • Creating skeleton tests
        • Covering all enum values
        • Test insertion order
        • Diffblue Sandbox
        • Environment Check Cache
      • Project configuration
        • General dependencies
        • Test framework dependencies
      • Cover Plugin settings
        • Test Naming
        • Test Formatting
        • Spring configuration options
        • Method Annotations
        • Test Directory
        • Reset Cover Plugin settings
      • Cover Plugin admin
        • Core Maintenance
        • Cover Plugin toolbar menu
        • Cover Plugin status bar widget
        • Telemetry
        • Memory management
        • Using SonarQube with Cover Plugin
        • Log files
        • Troubleshooting
    • Cover CLI
      • Writing tests
        • Command summary
        • Test examples
        • Creating partial tests
        • Customizing test inputs
        • Customizing test setup
        • Test naming
        • Test formatting
        • Test insertion order
        • Patch files
        • Diffblue Sandbox
        • Operational behaviors
        • Test validation
      • Project configuration
        • Preflight checks
        • General dependencies
        • Test framework dependencies
        • Compiling your project successfully
          • Building a Maven project
          • Building a Gradle project
        • Configuring Cover to work with your project's build system
          • Quick guide
          • Configuration file in detail
          • Getting Started with Ant Projects
          • Default configuration
        • Mocking using Mockito
        • Spring profiles
        • Runtime environment
      • Commands & Arguments
        • Environment configuration for CI
        • Packages, classes, and methods
        • Quoting command line arguments
        • Argument files
      • Cover CLI admin
        • Core Maintenance
        • Telemetry
        • Memory management
        • Using Cover CLI in Eclipse
        • Using SonarQube with Cover CLI
        • Log files
        • Troubleshooting
      • Environment Configuration
    • Cover Pipeline
      • Cover Pipeline for CI
        • Quick Start - General
        • Quick Start - Jenkins
        • Quick Start - Azure Pipelines
        • Quick Start - AWS Codebuild
        • Integrating Diffblue Cover into CI on pull requests
        • Installation - VMs or CI run
      • Cover Pipeline for GitLab
        • Introduction
        • Installation and initial setup
        • GitLab workflow
        • Configuration
        • Troubleshooting
        • Related topics
      • Cover Pipeline for GitHub
        • Introduction
        • Installation and initial setup
        • GitHub workflow
        • Configuration
        • Troubleshooting
        • Related topics
    • Cover Reports
      • Cover Reports Contributor
        • Java project config (JaCoCo)
        • Generate and upload reports bundles
        • Authenticated uploads
      • Cover Reports User
        • Navigation
        • Dashboards
        • Telemetry data
        • Export API
        • Considerations
      • Cover Reports Administrator
        • Install and update Cover Reports
        • Configuration options
        • Database backup
        • SSO with Cover Reports
        • Uninstall Cover Reports
    • Cover Optimize
      • Get started - Cover Optimize
      • Cover Optimize & Gradle
      • Cover Optimize & Maven
      • Patch files
    • Cover Refactor
      • Get started - Cover Refactor
    • Cover Annotations
      • Mocking Annotations
      • Custom Input Annotations
      • Interesting Value Annotations
    • Output Codes
      • E - Environment Codes
      • L - License Codes
      • R - Reason Codes
      • T - Testability Codes
      • V - Validation Codes
      • Working with output codes
        • Working with code E020
        • Working with codes E057 to E065
        • Working with code E085
        • Working with code R005
        • Working with code R006
        • Working with code R008
        • Working with code R011
        • Working with code R012
        • Working with code R013
        • Working with code R026
        • Working with code R031
        • Working with code V003
    • Tutorials
      • How to measure test quality
      • How to improve code coverage
      • How to test a new feature
      • How to find regressions
      • How to use Diffblue Cover in test driven development (TDD)
      • How to write tests for Kotlin projects
      • Examples of tests created by Diffblue Cover
      • Best practices for testing private methods
  • Updates & Upgrades
    • Update Cover
    • Cover Editions
    • What's new
    • Release archive
      • 2025-05-01
      • 2025-04-02
      • 2025-04-01
      • 2025-03-02
      • 2025-03-01
      • 2025-02-02
      • 2025-02-01
      • 2025-01-02
      • 2025-01-01
      • 2024-12-02
      • 2024-12-01
      • 2024-11-02
      • 2024-11-01
      • 2024-10-02
      • 2024-10-01
      • 2024-09-02
      • 2024-09-01
      • 2024-08-02
      • 2024-08-01
      • 2024-07-04
      • 2024-07-03
      • 2024-07-01
      • 2024-06-02
      • 2024-06-01
      • 2024-05-02
      • 2024-05-01
      • 2024-04-02
      • 2024-04-01
      • 2024-03-02
      • 2024-03-01
      • 2024-02-02
      • 2024-02-01
      • 2024-01-02
      • 2024-01-01
      • 2023-12-02
      • 2023-12-01
      • 2023-11-03
      • 2023-11-02
      • 2023-11-01
      • 2023-10-02
      • 2023-10-01
      • 2023-09-02
      • 2023-09-01
      • 2023-08-02
      • 2023-08-01
      • 2023-07-03
      • 2023-07-02
      • 2023-07-01
      • 2023-06-02
      • 2023-06-01
      • 2023-05-02
      • 2023-05-01
      • 2023-04-02
      • 2023-04-01
      • 2023-03-02
      • 2023-03-01
      • 2023-02-02
      • 2023-02-01
      • 2023-01-02
      • 2023-01-01
      • 2022-12-02
      • 2022-12-01
      • 2022-11-02
      • 2022-11-01
      • 2022-10-03
      • 2022-10-02
      • 2022-10-01
      • 2022-09-02
      • 2022-09-01
      • 2022-08-05
      • 2022-08-03
      • 2022-08-02
      • 2022-08-01
      • 2022-07-02
      • 2022-07-01
      • 2022-06-02
      • 2022-06-01
      • 2022-05-02
      • 2022-05-01
      • 2022-04-02
      • 2022-04-01
      • 2022-03-02
      • 2022-03-01
      • 2022-02-02
      • 2022-02-01
      • 2022-01-02
      • 2022-01-01
      • 2021-06-02
      • 2021-02-01
  • Legal
    • Diffblue Legal
      • Diffblue End User License Agreement (EULA)
      • Cover Third Party Notices and/or Licenses
      • Privacy Notice
Powered by GitBook
On this page
  • Overview
  • 1. Configuring and downloading Diffblue Cover CLI
  • 2. Running Diffblue Cover CLI
  • Integrating with Diffblue Cover Reports

Was this helpful?

Export as PDF
  1. Features
  2. Cover Pipeline
  3. Cover Pipeline for CI

Quick Start - Jenkins

PreviousQuick Start - GeneralNextQuick Start - Azure Pipelines

Last updated 3 months ago

Was this helpful?

Overview

This guide explains how to use Diffblue Cover to write tests in Jenkins CI. Note that this guide focuses on the specifics of Jenkinsfile configuration, for more details on configuring Diffblue Pipeline for CI see Quick Start - General. This guide assumes that you have:

  • A Maven or Gradle project that:

    • Compiles

    • Does not have non-compiling or failing tests

    • Triggers Jenkins CI on push or pull request with a declarative Jenkinsfile

  • A basic understanding of Jenkins

  • The ability to add credentials to, and generally manage, the Jenkins server

  • Access to download Diffblue Cover along with the license key (or pre-installed and activated in your CI machines). See . Note: alternatively access to download Docker files.

The rest of this guide assumes that you already have your project set to build (and test) in a CI environment. Typically, this would be a script that downloads your project from the repository, builds the project, and performs testing/checking. The steps below are to incorporate Diffblue Cover into this CI pipeline. If you are starting from scratch, you should do the above first to save trying to understand and configure your project and Diffblue Cover concurrently.

To integrate Diffblue Cover into your CI pipeline, we will guide you through creating a Jenkinsfile that adds the following to change request push events (not that configuration of the event/hook is not included on this page):

  1. Configures and downloads Diffblue Cover CLI

  2. Runs Diffblue Cover to:

    • build the project

    • activate your Diffblue Cover license

    • create tests

    • commit the created tests

    • push the tests back to the repository

Additionally this guide describes how to configure Diffblue Pipeline to integrate with Diffblue Cover Reports to upload coverage information. Report generation and upload should be performed on merge events, or on a regular basis (e.g. nightly).

The following sections provide more details for each of the above steps. After completing this guide, you can continue on to further examples of adding Diffblue Cover to your CI pipeline in an automated way.

1. Configuring and downloading Diffblue Cover CLI

Note that this section should be added into any step where you required Diffblue Cover CLI; this includes both writing tests and generating reports.

This section assumes you wish to install Diffblue Cover CLI into an existing agent /environment. If you wish to use Diffblue Cover CLI inside a Diffblue provided docker image, see the hint box at the end of the section. To configure Diffblue Cover CLI you will need to add some environment variables. This section introduces the minimal recommended for ease of configuration, for full details of available variables and their use see Environment configuration for CI.

Add a secret text credentials with id diffblue-cover-license-key and set the value to your Diffblue Cover license key.

environment {
    DIFFBLUE_RELEASE_URL = 'https://release.diffblue.com/cli/latest'
    DIFFBLUE_LICENSE_KEY = credentials('diffblue-cover-license-key')
}

In your Jenkinsfile, add the Jenkins stage Use dcover cli in Jenkins to the Jenkinsfile. Make sure to check, and if necessary modify, the download and install commands for your CI environment.

pipeline {
    agent any

    stages {
        stage('Use dcover cli in Jenkins') {
            steps {
                sh '''
                echo "Get and unzip dcover jars into directory dcover, store dcover script location for later use"
                mkdir --parents dcover
                wget "$DIFFBLUE_RELEASE_URL" --output-document dcover/dcover.zip --quiet
                unzip -o dcover/dcover.zip -d dcover
                DIFFBLUE_COVER_LOCATION="dcover/dcover"
                '''
            }
        }
    }

}

This will put the Diffblue Cover files into the dcover directory in the root of the workspace. The Diffblue Cover files contain a script to invoke dcover which has the relative path dcover/dcover. This is stored in the variable DIFFBLUE_COVER_LOCATION.

Diffblue Cover Docker agent

An alternative is to specify the Jenkins agent to use a Diffblue Cover CLI Docker image. The changes to the above configuration are as follows:

  1. The environment variable DIFFBLUE_RELEASE_URL is no longer required.

  2. The above steps to download and install Diffblue Cover CLI are no longer be required.

2. Running Diffblue Cover CLI

Note that this section should be added into change request push events in your CI work flows.

As above, this section describes how to use the installed Diffblue Cover CLI on an existing agent. For the Diffblue Cover Docker agent, see the box at the end for changes.

Now that Diffblue Cover CLI is installed in Jenkins you can use it to: build the project; create tests; commit the created tests; and push the tests back to the repository. In the script started above in the Jenkinsfile, append the following.

stages {
    stage('Use dcover cli in Jenkins') {
        steps {
            sh '''
                ...

                echo "Running dcover to create and commit tests"
                "$DIFFBLUE_COVER_LOCATION" ci activate build validate create

            '''
        }
    }
}

This will:

  • "$DIFFBLUE_COVER_LOCATION": Start Diffblue Cover.

  • ci : Enable CI behavior and git integration using environment configuration described above.

  • activate : Activate your Diffblue Cover license locally for use in CI.

  • build: Build the project using standard maven or gradle commands. Note that the build argument can be omitted and the project built before running Diffblue Cover. This is advisable if the project has non-trivial build configuration or specification.

  • validate : Validate existing Diffblue Cover tests and ensure they are updated.

  • create : Create tests as per the mode configuration

Push the changes so this pipeline runs. Once successfully complete, you should expect to see output commits by Diffblue Cover CLI on the pull request adding tests to the branch.

If you don't see this output, the call may need small modification for your project or dependencies adding until it works. The output gives you warnings along the way to guide you. See CLI Commands for more information.

For more details on these commands and their tuning with various arguments see Commands & Arguments.

Diffblue Cover Docker agent

The only changes necessary are to replace "$DIFFBLUE_COVER_LOCATION" with dcover as the Docker image will already have Diffblue Cover CLI installed and on the path.

Note that Cover Reports integration with Diffblue Cover Pipeline is only supported for writing baseline tests. Generating coverage reports and uploading them from runs in skip or patch mode is unsupported and will yield incomplete report data.

Integrating with Diffblue Cover Reports

Note that this section should be added into change merge events in your CI workflows, or alternatively on a regular job such as a nightly or weekly build. The prerequisites for this is the 1. Configuring and downloading Diffblue Cover CLI section above.

Diffblue Cover can generate coverage reports for your project and upload them to your instance of Cover Reports. This is done with the following script

stages {
    stage('Generate dcover cover reports in Jenkins') {
        steps {
            sh '''
                ...

                echo "Running dcover to generate reports"
                "$DIFFBLUE_COVER_LOCATION" coverage-reports upload <Reports Server URL>

            '''
        }
    }
}

This will:

  • "$DIFFBLUE_COVER_LOCATION": Start Diffblue Cover.

  • coverage-reports : Create the coverage reports bundle to send to Reports

  • upload : Upload the created reports bundle to the Reports server where<ReportsServerURL> is the URL of Cover Reports where the bundle will be uploaded.

Note that generating coverage reports should be performed as a separate step/action after test creation. It is possible to chain coverage-reports upload to the dcover ci command above, but this is not recommended.

Cover Reports must be installed on a server that is accessible from the CI runner.

Diffblue Cover Docker agent

The only changes necessary are to replace "$DIFFBLUE_COVER_LOCATION" with dcover as the Docker image will already have Diffblue Cover CLI installed and on the path.

This guide assumes that you have a URL with the Diffblue Cover CLI release zip (or you can use ) and the license key for online activation during the CI run. Alternatively, Diffblue Cover CLI can be pre-installed on the machines running CI with online activation. See . If the machines running CI are not able to access the internet for activation, pre-installing Diffblue Cover with offline activation may be possible if your license allows it. See Licensing.

Replace the agent any with agent diffblue/cover-cli:latest-jdk17 or other Docker image. The other images are produced for each supported JDK version. Go to for details. Note: To use the latest version of Diffblue Cover, use one of the latest-jdk tags. To use a specific release version, use one of the yyyy.mm.dd-jdk tags.

For more details on these commands and their tuning with various arguments see

Installation
https://release.diffblue.com/cli/latest
Installation
https://hub.docker.com/r/diffblue/cover-cli
Cover Reports Contributor