Xegara
Xegara

Reputation: 131

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?

Upvotes: 3

Views: 755

Answers (1)

VonC
VonC

Reputation: 1324977

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>

Upvotes: 5

Related Questions