Configuration
There are four key components for configuring Cover Pipeline for GitLab:
Labels: Pre-defined Diffblue Cover project labels to determine test requirements on merge requests (full baseline, update, or skip).
Integration Config: Direct license key and access token config using the Diffblue Cover integration page on GitLab.
Pipeline Config: Configure the Diffblue Cover section of your pipeline including Cover version, build config, and Cover commands to execute on merge requests.
Masked Variables: Define the Diffblue Cover license key and GitLab access token using GitLab masked variables. This avoids the need to configure the integration directly from the GitLab Integrations page.
Labels
When writing tests, Diffblue Cover will respond to specific project labels:
Diffblue Cover: Baseline Used to mark a merge request as requiring a full suite of tests to be written. This overrides the default behavior where Cover will only write tests related to the code changes already in the merge request. The baseline label is applied automatically when running Diffblue Cover for the first time on a project (to create the initial baseline test suite). On subsequent runs, you can select this label within a merge request, if required - useful when you want to refresh your entire test suite, such as when new product enhancements are released (to update the entire test suite with the latest enhancements).
Diffblue Cover: Skip Used to mark a merge request as requiring no tests to be written. The skip label is useful when performing merge requests that have no impact on unit tests, such as updates to comments only.
These labels are created automatically in GitLab when running Diffblue Cover for the first time on a project.
Integration config
You can configure the Diffblue license key and associated GitLab access token directly, using the Diffblue Cover integration page on GitLab. Note that, if preferred, you can use GitLab masked variables to define these properties - see Masked variables.
From your project in GitLab go to Settings > Integrations, find Diffblue Cover, and click Configure.
In the configuration screen, update the following (some items may be pre-selected):
Check/tick the Active box.
Enter your Diffblue Cover License key provided in your welcome email or by your organization. If needed, click the Try Diffblue Cover link to sign up for a free trial.
Enter details of your GitLab access token (Name and Secret) to allow Diffblue Cover to access your project. In general, use a GitLab Project Access Token with a
Developer
role, plusapi
andwrite_repository
scopes/permissions. If necessary you can use Group Access or Personal Access Tokens, again withapi
andwrite
permissions. See the GitLab docs links below for full details on how to create an access token.
Using an access token with excessive permissions is a security risk. If you use a Personal access token, consider creating a dedicated user with access limited to just the project, minimizing the impact of the token being leaked.
When you're done, click Save changes to apply your updates. Your Diffblue Cover integration is now now Active and ready for use in your projects.
Pipeline config
Update or create the .gitlab-ci.yml
file for your project to configure the Diffblue Cover section of your CI/CD pipeline.
From your project in GitLab go to Build > Pipeline editor and click Configure pipeline to create/edit the
.gitlab-ci.yml
file.In the editor, click Browse templates and search for the Diffblue Cover pipeline template file. Copy the contents of this file (sample below) to your project
.gitlab-ci.yml
pipeline file, and update if needed. Configurable properties are listed below - for everything else, please leave these set to the values defined in the Diffblue template.
Property | Description |
---|---|
| Select the Cover CLI docker image to use with your CI tool. Tag variations are provided for each supported JDK version - see https://hub.docker.com/r/diffblue/cover-cli for details. To use the latest version of Diffblue Cover, use one of the |
| Diffblue Cover requires the project to be built before creating any tests. Either specify the build command here (Maven and Gradle examples provided in the template) or provide pre-built artifacts via a job dependency. |
| Diffblue Cover commands and options to run. Core example provided in the template:
Configurable components:
|
For reference, the Diffblue Cover pipeline template is shown below. Note that this is a sample only - use the file provided in the GitLab templates repo to ensure that you have the latest version.
Masked variables
You can configure the Diffblue license key and associated GitLab access token using GitLab masked variables. Note that, if preferred, you can configure these properties directly, using the Diffblue Cover integration page on GitLab - see Integration config.
You only need to create these variables once - group variables can be used across all projects, project variables can be used within an individual project.
To add or update variables in the project or group settings (also see the Variables GitLab docs topic if needed):
In your group or project go to Settings > CI/CD and expand the Variables section.
Select Add variable and create each variable:
Key: Name of the variable. The three Diffblue variables to create are
DIFFBLUE_LICENSE_KEY
,DIFFBLUE_ACCESS_TOKEN_NAME
, andDIFFBLUE_ACCESS_TOKEN
. Note that offline licenses can also optionally be configured via environment variables, see below.Value: Value for the variable:
DIFFBLUE_LICENSE_KEY
- enter your Diffblue Cover License Key provided in your welcome email or by your organization.DIFFBLUE_ACCESS_TOKEN_NAME
, andDIFFBLUE_ACCESS_TOKEN
- enter details of your GitLab access token (Name and Secret) to allow Diffblue Cover to access your project. In general, use a GitLab Project Access Token with aDeveloper
role, plusapi
andwrite_repository
permissions. If necessary you can use Group Access or Personal Access Tokens, again withapi
andwrite
permissions. See the GitLab docs links below for full details on how to create an access token.
Optional: Note that if you have an offline license and wish to configure the offline license activation file this can be done by using the environment variable
DIFFBLUE_OFFLINE_LICENSE_ACTIVATION_FILE_CONTENTS
containing the contents of your offline license activation filels_activation.lic
Type: Set to
Variable
.Environment scope: Optional.
All
, or specific environments.Protect variable Optional. If selected, the variable is only available in pipelines that run on protected branches or protected tags.
Mask variable Select this option. This will mask the variable’s Value in job logs.
After you create a variable, you can use it in your .gitlab-ci.yml
file or in job scripts.
Using an access token with excessive permissions is a security risk. If you use a Personal access token, consider creating a dedicated user with access limited to just the project, minimizing the impact of the token being leaked.
Log files
Diffblue Cover log files are saved to a .diffblue/
directory in the pipeline artifacts (as defined in the .gitlab-ci.yml
file), and are available for download once the pipeline completes. These logs include user logs (also output during the run and visible in the job output) and support logs (if you ever require Diffblue support).
Last updated