Permalink
Browse files

JENKINS-47639 Display a message when missing coverage fails build

  • Loading branch information...
jeffpearce committed Oct 30, 2017
1 parent 70db38f commit 1c2ef417ce0f342f5eb400870e2b47adb3153d40
@@ -17,7 +17,6 @@
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
@@ -42,19 +41,21 @@
private transient Run<?, ?> owner;
private CoverageTarget healthyTarget;
private CoverageTarget unhealthyTarget;
private boolean failUnhealthy;
private boolean failUnstable;
private boolean autoUpdateHealth;
private boolean autoUpdateStability;
private boolean zoomCoverageChart;
private int maxNumberOfBuilds;
private final boolean failUnhealthy;
private final boolean failUnstable;
private final boolean autoUpdateHealth;
private final boolean autoUpdateStability;
private final boolean zoomCoverageChart;
private final int maxNumberOfBuilds;
/**
* Overall coverage result.
*/
private Map<CoverageMetric, Ratio> result;
private HealthReport health = null;
private transient WeakReference<CoverageResult> report;
private boolean onlyStable;
private final boolean onlyStable;

private String failMessage = null;

/**
* {@inheritDoc}
@@ -158,6 +159,25 @@ private synchronized void setOwner(Run<?, ?> owner) {
}
}

/**
* Getter for property 'failMessage'
*
* @return Value for property 'failMessage'
*/
public String getFailMessage() {
return failMessage;
}

/**
* Setter for property 'failMessage'
*
* @param failMessage value to set for 'failMessage'
*/
public void setFailMessage(String failMessage) {
this.failMessage = failMessage;
}


public Map<CoverageMetric, Ratio> getResults() {
return result;
}
@@ -42,7 +42,6 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import jdk.nashorn.internal.ir.BreakableNode;

import net.sf.json.JSONArray;
import net.sf.json.JSONException;
@@ -635,6 +634,7 @@ public void perform(Run<?, ?> build, FilePath workspace, Launcher launcher, fina
listener.getLogger().println("Setting Build to unstable.");
build.setResult(Result.UNSTABLE);
} else {
action.setFailMessage(String.format("Build failed because following metrics did not meet stability target: %s.", failingMetrics.toString()));
throw new AbortException("Failing build due to unstability.");
}
}
@@ -649,6 +649,7 @@ public void perform(Run<?, ?> build, FilePath workspace, Launcher launcher, fina
setHealthyPercent = unhealthyTarget.getSetPercent(result, metric);
listener.getLogger().println(" " + metric.getName() + "'s health is " + roundDecimalFloat(oldHealthyPercent * 100f) + " and set minimum health is " + roundDecimalFloat(setHealthyPercent * 100f) + ".");
}
action.setFailMessage(String.format("Build failed because following metrics did not meet health target: %s.", unhealthyMetrics.toString()));
throw new AbortException("Failing build because it is unhealthy.");
}
}
@@ -11,6 +11,12 @@
&amp;nbsp;
</j:forEach>
</div>
<j:set var="failMessage" value="${it.failMessage}" />
<j:if test="${failMessage != null}">
<div style="margin: 0 0 0 1ex">
${failMessage}
</div>
</j:if>
</j:if>
</t:summary>
</j:jelly>

0 comments on commit 1c2ef41

Please sign in to comment.