def b = manager.build;
def action = b.getActions().find { it.getUrlName() == "jacoco" }
if (action == null) {
manager.listener.logger.println "Unable to get Jacoco Build Action on build, so bailing out"
return;
}
def publishers = b.getProject().publishersList;
def jacocoPublisher = publishers.find { it.getDescriptor().getId() == "hudson.plugins.jacoco.JacocoPublisher" }
def line = action.getLineCoverage();
def clazz = action.getClassCoverage();
def method = action.getMethodCoverage();
def instruction = action.getInstructionCoverage();
def branch = action.getBranchCoverage();
def thresholds = action.getThresholds();
int percent = clazz.getPercentage();
manager.listener.logger.println "Observed class coverage: ${percent}%"
if (percent > thresholds.getMinClass()) {
manager.listener.logger.println "Increasing minimum threshold to observed value for class coverage"
thresholds.setMinClass(percent);
}
percent = method.getPercentage();
manager.listener.logger.println "Observed methods coverage: ${percent}%"
if (percent > thresholds.getMinMethod()) {
manager.listener.logger.println "Increasing minimum threshold to observed value for methods coverage"
thresholds.setMinMethod(percent);
}
percent = branch.getPercentage();
manager.listener.logger.println "Observed branches coverage: ${percent}%"
if (percent > thresholds.getMinBranch()) {
manager.listener.logger.println "Increasing minimum threshold to observed value for branches coverage"
thresholds.setMinBranch(percent);
}
percent = line.getPercentage();
manager.listener.logger.println "Observed lines coverage: ${percent}%"
if (percent > thresholds.getMinLine()) {
manager.listener.logger.println "Increasing minimum threshold to observed value for lines coverage"
thresholds.setMinLine(percent);
}
percent = instruction.getPercentage();
manager.listener.logger.println "Observed instruction coverage: ${percent}%"
if (percent > thresholds.getMinInstruction()) {
manager.listener.logger.println "Increasing minimum threshold to observed value for instruction coverage"
thresholds.setMinInstruction(percent);
}
def c = Class.forName("hudson.plugins.jacoco.JacocoPublisher", true, manager.hudson.getPluginManager().uberClassLoader)
def constructor = c.getConstructor( [ String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, boolean ] as Class[] )
def newPub = constructor.newInstance(jacocoPublisher.getExecPattern(), jacocoPublisher.getClassPattern(), jacocoPublisher.getSourcePattern(),
jacocoPublisher.getInclusionPattern(), jacocoPublisher.getExclusionPattern(), jacocoPublisher.getMaximumInstructionCoverage(),
jacocoPublisher.getMaximumBranchCoverage(), jacocoPublisher.getMaximumComplexityCoverage(), jacocoPublisher.getMaximumLineCoverage(),
jacocoPublisher.getMaximumMethodCoverage(), jacocoPublisher.getMaximumClassCoverage(), Integer.toString(thresholds.getMinInstruction()), Integer.toString(thresholds.getMinBranch()),
Integer.toString(thresholds.getMinComplexity()), Integer.toString(thresholds.getMinLine()), Integer.toString(thresholds.getMinMethod()), Integer.toString(thresholds.getMinClass()),
jacocoPublisher.isChangeBuildStatus())
publishers.replace(jacocoPublisher, newPub); b.getProject().save();
Because I've had to work around this myself in the meantime, I use the following groovy postbuild script to achieve this: