We have 3 stages [Build, Test, Publish]
The step “Publish Coverage Report” in Test stage sometimes fail when the coverage drops.
Problem 1: The Step is not shown as Failed
Problem 2: Though the build itself fails, it still runs the Publish stage after Test stage fails.
Even though the step is not shown as failed, the overall build fails, and is shown as failed.
I wonder if this might be a bug?
Is there a way to prevent it to run the Publish Stage if the publish coverage report fails?
Jenkins 2.319.3
Code Coverage API Plugin 2.0.4
The Declarative Pipeline:
agent {
docker {
alwaysPull true
args "--net=host ${dockerUtility.getProperties()}"
image 'nexus.company.com:38380/arm/dev:latest'
label 'docker-agent'
registryUrl 'https://nexus.company.com:38380/'
}
}
environment {
PATH = "$PATH:$HOME/.local/bin"
}
options {
gitLabConnection('COMPANY GitLab')
gitlabBuilds(builds: ['Build', 'Test', 'Publish'])
}
stages {
stage('Build') {
steps {
cmake arguments: '.', installation: 'InSearchPath'
cmakeBuild installation: 'InSearchPath', steps: [[withCmake: true]]
cpack installation: 'InSearchPath'
}
post {
success {
updateGitlabCommitStatus name: 'Build', state: 'success'
}
failure {
updateGitlabCommitStatus name: 'Build', state: 'failed'
}
}
}
stage('Test') {
steps {
sh 'make coverage'
publishCoverage(adapters: [
coberturaAdapter(path: "tests/coverage.xml", thresholds: [
[thresholdTarget: 'Group', unhealthyThreshold: 100.0],
[thresholdTarget: 'Package', unhealthyThreshold: 100.0],
[thresholdTarget: 'File', unhealthyThreshold: 85.0],
[thresholdTarget: 'Class', unhealthyThreshold: 85.0],
[thresholdTarget: 'Method', unhealthyThreshold: 85.0],
[thresholdTarget: 'Instruction', unhealthyThreshold: 85.0],
[thresholdTarget: 'Line', unhealthyThreshold: 85.0],
[thresholdTarget: 'Conditional', unhealthyThreshold: 85.0]
])
], calculateDiffForChangeRequests: true, failBuildIfCoverageDecreasedInChangeRequest: true, sourceFileResolver: sourceFiles('STORE_LAST_BUILD'), tag: 'Cobertura')
}
post {
success {
updateGitlabCommitStatus name: 'Test', state: 'success'
}
failure {
updateGitlabCommitStatus name: 'Test', state: 'failed'
}
}
}
stage('Publish') {
steps {
releaseUtility.tagRelease()
publishUtility.publishPackage()
archiveArtifacts artifacts: '*.deb', allowEmptyArchive: false, fingerprint: true
}
post {
success {
updateGitlabCommitStatus name: 'Publish', state: 'success'
}
failure {
updateGitlabCommitStatus name: 'Publish', state: 'failed'
}
}
}
}
post {
always {
deleteDir() /* clean up our workspace */
}
}
}