Skip to content

Commit

Permalink
JENKINS-47639 Display a message when missing coverage fails build
Browse files Browse the repository at this point in the history
  • Loading branch information
jxpearce-godaddy committed Oct 30, 2017
1 parent 70db38f commit 1c2ef41
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
36 changes: 28 additions & 8 deletions src/main/java/hudson/plugins/cobertura/CoberturaBuildAction.java
Expand Up @@ -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;
Expand All @@ -42,19 +41,21 @@ public class CoberturaBuildAction implements HealthReportingAction, StaplerProxy
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}
Expand Down Expand Up @@ -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;
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -635,6 +634,7 @@ unhealthyTarget, getOnlyStable(), getFailUnhealthy(), getFailUnstable(), getAuto
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.");
}
}
Expand All @@ -649,6 +649,7 @@ unhealthyTarget, getOnlyStable(), getFailUnhealthy(), getFailUnstable(), getAuto
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.");
}
}
Expand Down
Expand Up @@ -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.