Skip to content
Permalink
Browse files

[FIXED JENKINS-12342] Show results of failed builds if the plugin caused

the failure.
  • Loading branch information...
uhafner committed Feb 15, 2013
1 parent e37f9be commit e7ce3bc5e1c6c3b761c22fd5e240b46cf7ede41a
@@ -110,8 +110,8 @@ public AnnotationContainer getReferenceAnnotations() {

private ResultAction<? extends BuildResult> getAction(final boolean isStatusRelevant, final boolean mustBeStable) {
for (AbstractBuild<?, ?> build = baseline.getPreviousBuild(); build != null; build = build.getPreviousBuild()) {
if (hasValidResult(build, mustBeStable)) {
ResultAction<? extends BuildResult> action = getResultAction(build);
ResultAction<? extends BuildResult> action = getResultAction(build);
if (hasValidResult(build, mustBeStable, action)) {
if (action != null && (action.isSuccessful() || !isStatusRelevant)) {
return action;
}
@@ -165,9 +165,10 @@ public AnnotationContainer getReferenceAnnotations() {
}

private boolean hasValidResult(final AbstractBuild<?, ?> build) {
return hasValidResult(build, false);
return hasValidResult(build, false, null);
}
private boolean hasValidResult(final AbstractBuild<?, ?> build, final boolean mustBeStable) {

private boolean hasValidResult(final AbstractBuild<?, ?> build, final boolean mustBeStable, @CheckForNull final ResultAction<? extends BuildResult> action) {
Result result = build.getResult();

if (result == null) {
@@ -176,7 +177,16 @@ private boolean hasValidResult(final AbstractBuild<?, ?> build, final boolean mu
if (mustBeStable) {
return result == Result.SUCCESS;
}
return build.getResult().isBetterThan(Result.FAILURE);
return result.isBetterThan(Result.FAILURE) || isPluginCauseForFailure(action);
}

private boolean isPluginCauseForFailure(@CheckForNull final ResultAction<? extends BuildResult> action) {
if (action == null) {
return false;
}
else {
return action.getResult().getPluginResult().isWorseOrEqualTo(Result.FAILURE);
}
}

/**
@@ -73,11 +73,16 @@ public void testHasPreviousResult() throws Exception {
* <li>Build with no result</li>
* <li>Baseline</li>
* </ol>
* @throws Exception the exception
* If the plug-in caused the failure then there will be a result available, otherwise not.
*/
@Test
public void testHasPreviousResultDueToFailure() {
verifyHasResult(false, Result.SUCCESS);
verifyHasResult(true, Result.FAILURE);
}

@SuppressWarnings("rawtypes")
public void testHasNoPreviousResultDueToFailure() throws Exception {
private void verifyHasResult(final boolean expectedResult, final Result pluginResult) {
AbstractBuild withResult = mockBuild(Result.ABORTED);
AbstractBuild noResult = mockBuild();
AbstractBuild baseline = mockBuild();
@@ -91,9 +96,10 @@ public void testHasNoPreviousResultDueToFailure() throws Exception {
when(action.getResult()).thenReturn(result);
AnnotationContainer container = mock(AnnotationContainer.class);
when(result.getContainer()).thenReturn(container);
when(result.getPluginResult()).thenReturn(pluginResult);
BuildHistory history = createHistory(baseline);

assertFalse("Build has previous result", history.hasPreviousResult());
assertEquals("Build has previous result", expectedResult, history.hasPreviousResult());
}

@SuppressWarnings("rawtypes")
@@ -238,6 +244,8 @@ private BuildResult createFailureResult(final AbstractBuild withFailureResult) {
when(failureAction.isSuccessful()).thenReturn(false);
BuildResult failureResult = mock(BuildResult.class);
when(failureAction.getResult()).thenReturn(failureResult);
when(failureResult.getPluginResult()).thenReturn(Result.SUCCESS);

return failureResult;
}

@@ -250,6 +258,7 @@ private AnnotationContainer createSuccessfulResult(final AbstractBuild withSucce
AnnotationContainer container = mock(AnnotationContainer.class);
when(successResult.getContainer()).thenReturn(container);
when(successAction.getResult()).thenReturn(successResult);
when(successResult.getPluginResult()).thenReturn(Result.SUCCESS);
return container;
}

0 comments on commit e7ce3bc

Please sign in to comment.
You can’t perform that action at this time.