Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[FIXED JENKINS-12342] Show results of failed builds if the plugin caused
Browse files Browse the repository at this point in the history
the failure.
  • Loading branch information
uhafner committed Feb 15, 2013
1 parent e37f9be commit e7ce3bc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
20 changes: 15 additions & 5 deletions src/main/java/hudson/plugins/analysis/core/BuildHistory.java
Expand Up @@ -110,8 +110,8 @@ private ResultAction<? extends BuildResult> getAction(final boolean isStatusRele

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;
}
Expand Down Expand Up @@ -165,9 +165,10 @@ private ResultAction<? extends BuildResult> getPreviousAction() {
}

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) {
Expand All @@ -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);
}
}

/**
Expand Down
15 changes: 12 additions & 3 deletions src/test/java/hudson/plugins/analysis/core/BuildHistoryTest.java
Expand Up @@ -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();
Expand All @@ -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")
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit e7ce3bc

Please sign in to comment.