# Build is not getting fail when the jacoco coverage is met threshold

**URL:** https://community.jenkins.io/t/build-is-not-getting-fail-when-the-jacoco-coverage-is-met-threshold/8689
**Category:** Using Jenkins
**Tags:** pipeline
**Created:** [July 26, 2023, 11:10am UTC](https://community.jenkins.io/t/build-is-not-getting-fail-when-the-jacoco-coverage-is-met-threshold/8689 "2023-07-26T11:10:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Laddu](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/laddu/32/5013_2.png) [@Laddu](https://community.jenkins.io/u/Laddu)
#### Post date: [July 26, 2023, 11:10am UTC](https://community.jenkins.io/t/build-is-not-getting-fail-when-the-jacoco-coverage-is-met-threshold/8689/1 "2023-07-26T11:10:31Z")

</div>

Hi, I am using jacoco plugin to make sure if the coverage is less than 70 % then build should failed. for that i am using below script, but in logs of jacoco step getting failure but pipeline shows Green color, and it continues.

```auto
stage('Jacoco') {
                 steps {
                    script {
                        jacoco classPattern: '**/build/classes/java', changeBuildStatus: true, minimumInstructionCoverage: '70', maximumInstructionCoverage: '80'
                       if(env.BRANCH_NAME.equals('develop')) {
                          def publishResult = publishCoverage failUnhealthy: true,
						  globalThresholds: [[thresholdTarget: 'Instruction', unhealthyThreshold: 80.0]],
						  adapters: [jacocoAdapter(path: 'build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml')],
						  sourceFileResolver: sourceFiles('STORE_ALL_BUILD')
						  script {
							if (currentBuild.result == 'FAILURE') {
							error("Test coverage is too low.")
							}
							}
                       }
                    }
                 }
        }

```

In the log of jacoco step getting below message at the end :

> [JaCoCo plugin] Apply Min/Max thresholds result: FAILURE

Please suggest the solution

---

<div class="post-metadata">

### Author: ![Laddu](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/laddu/32/5013_2.png) [@Laddu](https://community.jenkins.io/u/Laddu)
#### Post date: [August 2, 2023, 5:11am UTC](https://community.jenkins.io/t/build-is-not-getting-fail-when-the-jacoco-coverage-is-met-threshold/8689/2 "2023-08-02T05:11:42Z")

</div>

anybody comment on this query

---

<div class="post-metadata">

### Author: ![poddingue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/poddingue/32/985_2.png) [@poddingue](https://community.jenkins.io/u/poddingue)
#### Post date: [August 2, 2023, 6:48am UTC](https://community.jenkins.io/t/build-is-not-getting-fail-when-the-jacoco-coverage-is-met-threshold/8689/3 "2023-08-02T06:48:14Z")

</div>

Hello @Laddu and welcome to this community 👋

The issue might be related to the placement of the error message inside the `script` block. The `script` block within the `jacoco` step is executed independently of the overall pipeline, which is maybe why the pipeline continues even though the JaCoCo step fails.

---

<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: [August 2, 2023, 11:07am UTC](https://community.jenkins.io/t/build-is-not-getting-fail-when-the-jacoco-coverage-is-met-threshold/8689/4 "2023-08-02T11:07:48Z")

</div>

Typically pipelines do not fail, plugins simply set the build status to unstable.

It is also unclear to me, why you are mixing two different coverage plugins? I would recommend to not use the deprecated step `publishCoverage` from the coverage plugin anymore, see [GitHub - jenkinsci/code-coverage-api-plugin: Jenkins Code Coverage Plugin](https://github.com/jenkinsci/code-coverage-api-plugin) for details. Additionally, you are also using the JaCoCo plugin to record the coverage. I think this one is not needed anymore, as the functionality has been integrated into the [code coverage plugin](https://github.com/jenkinsci/code-coverage-api-plugin).
