Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fail a maven build, if JUnit coverage falls below previous coverage?

I've read that we can configure JaCoCo to fail the maven build if the test code coverage is below a predefined threshold but how about if we want to fail the build if the test code coverage drops from the previous test code coverage?

like image 947
Xegara Avatar asked Dec 06 '25 17:12

Xegara


1 Answers

The Code Coverage API Jenkins plugin comes with a REST API which includes:

Coverage result of last build:

 …​/{buildNumber}/coverage/…​/last/result/api/\{json|xml\}?depth={number}

The idea would be to define a step for storing that value in a variable, and then use said variable in limit configuration:

<rules>
  <rule implementation="org.jacoco.maven.RuleConfiguration">
    <element>BUNDLE</element>
    <limits>
      <limit implementation="org.jacoco.report.check.Limit">
        <counter>INSTRUCTION</counter>
        <value>COVEREDRATIO</value>
        <minimum>${env.LAST_BULD_COVERAGE}</minimum>
      </limit>
like image 67
VonC Avatar answered Dec 08 '25 07:12

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!