def showCoverageReport( String xmlPath, Map targets = [:], Boolean failNoReports = true ) {
Map<String, String> benchmarks = [
conditional : '70, 0, 0' ,
line : '80, 0, 0' ,
method : '80, 0, 0' ,
branch : '60, 0, 0'
]
benchmarks = benchmarks << targets
def file = findFiles( glob: xmlPath )
if ( file.size() ) {
String report = file.first().path
println "coverage report file found in: ${report}"
cobertura coberturaReportFile: report ,
conditionalCoverageTargets: benchmarks.conditional ,
lineCoverageTargets: benchmarks.line ,
methodCoverageTargets: benchmarks.method ,
failNoReports: failNoReports ,
failUnhealthy: false,
failUnstable: false,
onlyStable: false,
autoUpdateStability: true,
autoUpdateHealth: false,
enableNewApi: false
} else {
error "Could not find cobertura xml report in pattern: ${xmlPath}"
}
}
recordCoverage qualityGates: [
[criticality: 'NOTE' , integerThreshold: 30 , metric: 'MODULE' , threshold: 30.0] ,
[criticality: 'NOTE' , integerThreshold: 30 , metric: 'PACKAGE' , threshold: 30.0] ,
[criticality: 'NOTE' , integerThreshold: 30 , metric: 'FILE' , threshold: 30.0] ,
[criticality: 'NOTE' , integerThreshold: 30 , metric: 'CLASS' , threshold: 30.0] ,
[criticality: 'NOTE' , integerThreshold: 30 , metric: 'METHOD' , threshold: 30.0] ,
[criticality: 'NOTE' , integerThreshold: 30 , metric: 'LINE' , threshold: 30.0] ,
[criticality: 'NOTE' , integerThreshold: 30 , metric: 'BRANCH' , threshold: 30.0] ,
[criticality: 'NOTE' , integerThreshold: 30 , metric: 'INSTRUCTION' , threshold: 30.0] ,
[criticality: 'NOTE' , integerThreshold: 30 , metric: 'MUTATION' , threshold: 30.0] ,
[criticality: 'NOTE' , integerThreshold: 30 , metric: 'TEST_STRENGTH' , threshold: 30.0] ,
[criticality: 'NOTE' , integerThreshold: 30 , metric: 'COMPLEXITY' , threshold: 30.0] ,
[criticality: 'NOTE' , integerThreshold: 30 , metric: 'COMPLEXITY_MAXIMUM' , threshold: 30.0] ,
[criticality: 'NOTE' , integerThreshold: 30 , metric: 'LOC' , threshold: 30.0] ,
[criticality: 'NOTE' , integerThreshold: 30 , metric: 'TESTS' , threshold: 30.0]
],
tools: [[parser: 'COBERTURA', pattern: '*.xml']]
recordCoverage checksAnnotationScope: 'ALL_LINES',
enabledForFailure: true,
ignoreParsingErrors: true,
qualityGates: [
[baseline: 'MODIFIED_LINES', criticality: 'NOTE', metric: 'LINE', threshold: 0.001]
],
skipSymbolicLinks: true,
sourceCodeRetention: 'EVERY_BUILD',
sourceDirectories: [[path: '../Src']],
tools: [[parser: 'COBERTURA', pattern: 'a.xml']]
def showCoverageReport( String xmlPath, String sourcePath = '**/src', Map targets = [:] ) {
Map<String, String> benchmarks = [
conditional : '70, 0, 0' ,
line : '80, 0, 0' ,
method : '80, 0, 0' ,
branch : '60, 0, 0'
]
benchmarks = benchmarks << targets
def file = findFiles( glob: xmlPath )
if ( file.size() ) {
String report = file.first().path
println "coverage report file found: ${report}"
discoverReferenceBuild()
recordCoverage( name: 'Cobertura Coverage',
id: 'coverage',
tools: [[ parser: 'COBERTURA', pattern: xmlPath ]],
sourceDirectories: [[ path: sourcePath ]],
ignoreParsingErrors: true,
skipSymbolicLinks: false,
calculateDiffForChangeRequests: true,
failBuildIfCoverageDecreasedInChangeRequest: true,
sourceCodeRetention: 'EVERY_BUILD',
checksAnnotationScope: 'ALL_LINES',
qualityGates: [
[ threshold: benchmarks.line.split(',').first() , metric: 'LINE' , baseline: 'PROJECT' , criticality: 'UNSTABLE' ] ,
[ threshold: 0.01 , metric: 'LINE' , baseline: 'MODIFIED_LINES' , criticality: 'UNSTABLE' ] ,
[ threshold: benchmarks.branch.split(',').first() , metric: 'BRANCH' , baseline: 'PROJECT' , criticality: 'UNSTABLE' ]
]
)
} else {
error( "Could not find cobertura xml report in pattern: ${xmlPath}" )
}
}