A plugin to extract metrics from coverage reports generated by different coverage tools.
The following settings changes this plugin's behavior.
Input Parameter | Description |
---|---|
tool | Which tools will be used during the plugin execution. |
The allowed values: | |
- jacoco | |
- jacoco-xml | |
fail_on_threshold | Check this to set the build status to failed if coverage thresholds are violated. |
fail_if_no_reports | Set this to indicate if the plugin should fail if no reports are found for the reports path. |
reports_path_pattern | Path to the reports files generated by the tools chosen. Supports multiple Glob patterns separated by comma. |
class_directories | Path to the Java class directories that should be included in coverage reporting. Can have multiple patterns separated by comma. Supports Glob. |
class_exclusion_pattern | Path to the Java class files that should be excluded from coverage reporting. Can have multiple patterns separated by comma. Supports Glob. |
class_inclusion_pattern | Path to the Java class files that should be included in coverage reporting. Can have multiple patterns separated by comma. Supports Glob. |
skip_source_copy | Check this to disable display of source files for each line coverage. |
source_directories | Path to the Java source directories that should be included in coverage reporting. Can have multiple patterns separated by comma. Supports Glob. |
source_inclusion_pattern | Path to the Java source files that should be included in coverage reporting. Supports Glob. It could be a list separated by comma. |
source_exclusion_pattern | Path to the Java source files that should be excluded from coverage reporting. Supports Glob. It could be a list separated by comma. |
threshold_class | Covered and missed classes (given as percentage). This represents the minimum % of coverage for classes. |
threshold_method | Covered and missed methods (given as percentage). This represents the minimum % of coverage for methods. |
threshold_line | Line coverage (given as percentage). This represents the minimum % of coverage for lines. |
threshold_instruction | Instruction coverage (given as percentage). This represents the minimum % of coverage for instructions. |
threshold_branch | Branch coverage or decision coverage (given as percentage). This represents the minimum % of coverage for branches/conditionals. |
threshold_complexity | Cyclomatic complexity (given as absolute number). This represents the maximum value for the complexity. |
threshold_module | Covered and missed modules (given as percentage). This represents the minimum % of coverage for the module. |
threshold_package | Covered and missed packages; also used for namespaces or directories (given as percentage). This represents the minimum % of coverage for the packages. |
threshold_file | Covered and missed files (given as percentage). This represents the minimum % of coverage for the file. |
threshold_complexity_density | Cyclomatic complexity density (given as relation between cyclomatic complexity and lines of code). This represents the maximum value for the complexity density. |
threshold_loc | Lines of code (given as absolute number). This represents the minimum value for the line of code. |
Below is a jacoco tool example .drone.yml
that uses this plugin.
step:
type: Plugin
name: jacocoSample
identifier: jacocoSample
spec:
connectorRef: Docker_Hub_Anonymous
image: 'plugins/coverage-report'
settings:
tool: jacoco
reports_path_pattern: '**/target/jacoco.exec'
fail_on_threshold: 'true'
fail_if_no_reports: 'false'
class_directories: '**/target/classes, **/WEB-INF/classes'
class_inclusion_pattern: '**/*.class, **/*.xml'
class_exclusion_pattern: '**/controllers/*.class'
source_directories: '**/src/main/java'
source_inclusion_pattern: '**/*.java, *.groovy'
source_exclusion_pattern: '**/controllers/*.java'
skip_source_copy: 'false'
threshold_instruction: '0'
threshold_branch: '0'
threshold_complexity: '80'
threshold_line: '0'
threshold_method: '0'
threshold_class: '0'
Below is a jacoco-xml tool example .drone.yml
that uses this plugin.
- step:
type: Plugin
name: jacoco_xml_sample
identifier: jacoco_xml_sample
spec:
connectorRef: Docker_Hub_Anonymous
image: 'plugins/coverage-report'
settings:
reports_path_pattern: '**/jacoco.xml'
threshold_instruction: '20'
threshold_branch: '100'
threshold_complexity: '75'
threshold_line: '20'
threshold_method: '20'
threshold_class: '20'
tool: jacoco-xml
fail_on_threshold: 'true'
Below is a cobertura tool example .drone.yml
that uses this plugin.
- step:
type: Plugin
name: cobertura_sample
identifier: cobertura_sample
spec:
connectorRef: Docker_Hub_Anonymous
image: 'plugins/coverage-report'
settings:
reports_path_pattern: '**/coverage.xml'
threshold_branch: '0'
threshold_class: '40'
threshold_line: '5.0'
threshold_method: '0'
threshold_package: '100'
threshold_file: '50.0'
threshold_loc: '15'
threshold_complexity: '10'
threshold_complexity_density: '0.50'
fail_on_threshold: 'true'
tool: cobertura
Build the plugin binary:
sh scripts/build.sh
Build the plugin image:
For amd64 use
docker build -t plugins/coverage-report -f docker/Dockerfile.linux.amd64 .
For arm64 use
docker build -t plugins/coverage-report -f docker/Dockerfile.linux.arm64 .
DRONE_OUTPUT should be set to "/tmp/drone-output" in non drone environment while testing
Execute the plugin from your current working directory:
To test jacoco plugin using docker image, run the following command:
docker run --rm \
-e PLUGIN_TOOL='jacoco' \
-e PLUGIN_REPORTS_PATH_PATTERN='**/target/jacoco.exec' \
-e PLUGIN_FAIL_ON_THRESHOLD='true' \
-e PLUGIN_FAIL_IF_NO_REPORTS='false' \
-e PLUGIN_CLASS_DIRECTORIES='**/target/classes, **/WEB-INF/classes' \
-e PLUGIN_CLASS_INCLUSION_PATTERN='**/*.class, **/*.xml' \
-e PLUGIN_CLASS_EXCLUSION_PATTERN='**/controllers/*.class' \
-e PLUGIN_SOURCE_DIRECTORIES='**/src/main/java' \
-e PLUGIN_SOURCE_INCLUSION_PATTERN='**/*.java, *.groovy' \
-e PLUGIN_SOURCE_EXCLUSION_PATTERN='**/controllers/*.java' \
-e PLUGIN_SKIP_SOURCE_COPY='false' \
-e PLUGIN_THRESHOLD_INSTRUCTION='0' \
-e PLUGIN_THRESHOLD_BRANCH='0' \
-e PLUGIN_THRESHOLD_COMPLEXITY='80' \
-e PLUGIN_THRESHOLD_LINE='0' \
-e PLUGIN_THRESHOLD_METHOD='0' \
-e PLUGIN_THRESHOLD_CLASS='0' \
-e PLUGIN_DRONE_WORKSPACE='/harness' \
-e PLUGIN_DRONE_OUTPUT='/tmp/drone-output' \
-w /drone/src \
-v $(pwd):/drone/src \
plugins/coverage-report
To test jacoco-xml plugin using docker image, run the following command:
docker run --rm \
-e PLUGIN_TOOL='jacoco-xml' \
-e PLUGIN_REPORTS_PATH_PATTERN='**/jacoco.xml' \
-e PLUGIN_FAIL_ON_THRESHOLD='true' \
-e PLUGIN_THRESHOLD_INSTRUCTION='20' \
-e PLUGIN_THRESHOLD_BRANCH='100' \
-e PLUGIN_THRESHOLD_COMPLEXITY='75' \
-e PLUGIN_THRESHOLD_LINE='20' \
-e PLUGIN_THRESHOLD_METHOD='20' \
-e PLUGIN_THRESHOLD_CLASS='20' \
-e PLUGIN_DRONE_WORKSPACE='/harness' \
-e PLUGIN_DRONE_OUTPUT='/tmp/drone-output' \
plugins/coverage-report
To test cobertura plugin using docker image, run the following command:
docker run --rm \
-e PLUGIN_TOOL='cobertura' \
-e PLUGIN_REPORTS_PATH_PATTERN='**/coverage.xml' \
-e PLUGIN_FAIL_ON_THRESHOLD='true' \
-e PLUGIN_THRESHOLD_BRANCH='100' \
-e PLUGIN_THRESHOLD_COMPLEXITY='75' \
-e PLUGIN_THRESHOLD_LINE='20' \
-e PLUGIN_THRESHOLD_METHOD='20' \
-e PLUGIN_THRESHOLD_CLASS='20' \
-e PLUGIN_THRESHOLD_PACKAGE='100' \
-e PLUGIN_THRESHOLD_FILE='50.0' \
-e PLUGIN_DRONE_WORKSPACE='/harness' \
-e PLUGIN_DRONE_OUTPUT='/tmp/drone-output' \
plugins/coverage-report
Parameter | Description |
---|---|
INSTRUCTION_COVERAGE |
Ratio of executed bytecode instructions over the total instructions calculated as percentage |
BRANCH_COVERAGE |
Percentage of branches executed in conditional statements (like if, else). |
LINE_COVERAGE |
Ratio of code lines executed over the total lines, calculated as percentage |
METHOD_COVERAGE |
Ratio of methods covered by tests over the total methods, calculated as percentage |
CLASS_COVERAGE |
Ratio of classes covered by tests over the total classes, calculated as percentage |
COMPLEXITY_COVERAGE |
Measures code complexity based on control flow paths and the Cyclomatic Complexity metric. |
Parameter | Description |
---|---|
BRANCH_COVERAGE |
Percentage of branches executed in conditional statements (like if, else). |
LINE_COVERAGE |
Ratio of code lines executed over the total lines, calculated as percentage |
COMPLEXITY_COVERAGE |
Measures code complexity based on control flow paths and the Cyclomatic Complexity metric. |
METHOD_COVERAGE |
Ratio of methods covered by tests over total methods, calculated as percentage |
CLASS_COVERAGE |
Ratio of classes covered by tests over total classes, calculated as percentage |
FILE_COVERAGE |
Coverage at the file level, indicating the extent to which each file is covered by tests. |
PACKAGE_COVERAGE |
Ratio of packages covered by tests over total coverage, calculated as percentage |
COMPLEXITY_DENSITY |
Ratio of complexity to lines of code, showing average complexity across the codebase. |
LOC |
Lines of Code, indicating the total number of lines in the codebase. |
This plugin can only be run on linux amd64/arm64. Windows build not supported.