Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public String getUrlName() {
}

private Set<AnalysisHistory> createBuildHistory() {
Run<?, ?> lastFinishedRun = owner.getLastCompletedBuild();
if (lastFinishedRun == null) {
Run<?, ?> lastBuild = owner.getLastBuild();
if (lastBuild == null) {
return new HashSet<>();
}
else {
return owner.getActions(JobAction.class)
.stream()
.map(JobAction::getId)
.map(id -> new AnalysisHistory(lastFinishedRun, new ByIdResultSelector(id)))
.map(id -> new AnalysisHistory(lastBuild, new ByIdResultSelector(id)))
.collect(Collectors.toSet());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ public String getTrendName() {
* @return the history
*/
public History createBuildHistory() {
Run<?, ?> lastCompletedBuild = owner.getLastCompletedBuild();
if (lastCompletedBuild == null) {
Run<?, ?> lastBuild = owner.getLastBuild();
if (lastBuild == null) {
return new NullAnalysisHistory();
}
else {
return new AnalysisHistory(lastCompletedBuild, new ByIdResultSelector(getId()));
return new AnalysisHistory(lastBuild, new ByIdResultSelector(getId()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void shouldShowIconIfThereIsABuildResultAvailable() throws IOException {
assertThat(action.getIconFileName()).isEqualTo(ICON); // a JobAction should always show an icon

Run<?, ?> reference = createValidReferenceBuild(0);
when(job.getLastCompletedBuild()).thenAnswer(i -> reference);
when(job.getLastBuild()).thenAnswer(i -> reference);

assertThat(action.getIconFileName()).isEqualTo(ICON);
assertThat(action.isTrendVisible()).isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,43 @@ private void assertActionProperties(final FreeStyleProject project, final Run<?,
assertThat(jobAction.getOwner()).isEqualTo(project);
assertThat(jobAction.getIconFileName()).endsWith(iconName);
}

@Test
@Issue("JENKINS-69273")
void shouldShowTrendChartWhenAllBuildsAreFailedButEnabledForFailure() {
var project = createFreeStyleProjectWithWorkspaceFilesWithSuffix(ECLIPSE_LOG);

var recorder = enableEclipseWarnings(project);
recorder.setEnabledForFailure(true);

addFailureStep(project);

Run<?, ?> first = buildWithResult(project, Result.FAILURE);
List<ResultAction> firstActions = first.getActions(ResultAction.class);
assertThat(firstActions)
.as("First FAILED build should have ResultAction when enabledForFailure=true")
.isNotEmpty();

ResultAction firstResultAction = firstActions.get(0);
JobAction firstJobAction = (JobAction) firstResultAction.getProjectActions().stream()
.filter(a -> a instanceof JobAction)
.findFirst()
.orElseThrow(() -> new AssertionError("JobAction must be available from ResultAction"));

assertThatTrendChartIsHidden(firstJobAction);

Run<?, ?> second = buildWithResult(project, Result.FAILURE);
List<ResultAction> secondActions = second.getActions(ResultAction.class);
assertThat(secondActions)
.as("Second FAILED build should have ResultAction when enabledForFailure=true")
.isNotEmpty();

ResultAction secondResultAction = secondActions.get(0);
JobAction secondJobAction = (JobAction) secondResultAction.getProjectActions().stream()
.filter(a -> a instanceof JobAction)
.findFirst()
.orElseThrow(() -> new AssertionError("JobAction must be available from ResultAction"));

assertThatTrendChartIsVisible(secondJobAction);
}
}
Loading