# Publish Coverage Report fails, but step show as success

**URL:** <https://community.jenkins.io/t/publish-coverage-report-fails-but-step-show-as-success/1849>\
**Category:** Using Jenkins\
**Created:** [March 18, 2022, 1:09pm UTC](https://community.jenkins.io/t/publish-coverage-report-fails-but-step-show-as-success/1849 "2022-03-18T13:09:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DJViking](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/djviking/32/907_2.png) [@DJViking](https://community.jenkins.io/u/DJViking)\
**Post date:** [March 18, 2022, 1:09pm UTC](https://community.jenkins.io/t/publish-coverage-report-fails-but-step-show-as-success/1849/1 "2022-03-18T13:09:37Z")

</div>

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:**

```nohighlight
  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 */
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![uhafner](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/uhafner/32/68_2.png) [@uhafner](https://community.jenkins.io/u/uhafner)\
**Post date:** [March 18, 2022, 1:23pm UTC](https://community.jenkins.io/t/publish-coverage-report-fails-but-step-show-as-success/1849/2 "2022-03-18T13:23:30Z")

</div>

Yes, this is a known bug:

> <https://github.com/jenkinsci/code-coverage-api-plugin/issues/177>
>
> Unless I've missed a possible setting somewhere, it looks like the settings to t…ell the coverage report to fail a build if the coverage metrics fail do fail the build, but don't flag the stage as failed. This means that by glancing at the pipeline display you can't tell that it was the coverage tests that failed. However the state is being handled, it seems to be outside the pipeline error/state handling since I don't seem to be able to override this behaviour with \`catchError\`/\`warnError\`/etc either.

---

<div class="post-metadata">

**Author:** ![DJViking](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/djviking/32/907_2.png) [@DJViking](https://community.jenkins.io/u/DJViking)\
**Post date:** [March 18, 2022, 1:38pm UTC](https://community.jenkins.io/t/publish-coverage-report-fails-but-step-show-as-success/1849/3 "2022-03-18T13:38:52Z")

</div>

Perhaps a workaround in the mean time.  
Checking for currentBuild.result before running any steps in the Publish stage.
