This plugin is an extension of the embeddable-build-status. It adds the ability to display coverage metrics badges for jobs and pipeline recording coverage using coverage plugin
The plugin offer new placeholders to display coverage badges in the build status badge.
It works only when the job or pipeline is reporting the coverage using recordCoverage
step from the coverage plugin
Following placeholder are
instructionCoverage
: Display the instruction coverage percentagebranchCoverage
: Display the branch coverage percentagelineOfCode
: Display the total line of codenumberOfTest
: Display the number of testcolorInstructionCoverage
: Display the color of the instruction coveragecolorBranchCoverage
: Display the color of the branch coverage
For example a coverage badge can be displayed like this
<instanceUrl>/buildStatus/icon?job=job&subject=Coverage&status=${instructionCoverage}&color=${colorInstructionCoverage}
It will render a badge like this (example with 50% coverage)
Or for the total line of code
<instanceUrl>/buildStatus/icon?job=test&status=${lineOfCode}&subject=line%20of%20code&color=blue
It will render a badge like this
Or even the number of test
<instanceUrl>/buildStatus/icon?job=test&status=${numberOfTest}&subject=Tests&color=brightgreen
It will render a badge like this
Please refer to the embeddable-build-status for more information about the different URL to access the badges.
If the Jenkins controller has a tool configured for "maven-3.9.6" and "jdk-21" and has the appropriate plugins installed, the following declarative Pipeline provides a working example:
pipeline {
agent {
label '!windows'
}
tools {
maven 'maven-3.9.6'
jdk 'jdk-21'
}
stages {
stage('Checkout') {
steps {
git 'https://github.com/jenkinsci/platformlabeler-plugin.git'
}
}
stage('Build & Test') {
steps {
sh 'mvn -P enable-jacoco clean verify'
}
}
}
post {
always {
recordCoverage tools: [[pattern: 'target/site/jacoco/jacoco.xml']]
echo 'Coverage results embeddable build status build URL is:\n' +
env.BUILD_URL + '/badge/icon' +
'?subject=Coverage&status=${branchCoverage}&color=${colorBranchCoverage}'
echo 'Coverage results embeddable build status job URL is:\n' +
env.JOB_URL + '/badge/icon' +
'?subject=Coverage&status=${branchCoverage}&color=${colorBranchCoverage}'
}
}
}
CONTRIBUTING file and make sure it is appropriate for your plugin, if not then add your own one adapted from the base file
Refer to our contribution guidelines
Licensed under MIT, see LICENSE