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

Viewed 194
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>
Related