Skip to content

Commit 4cff9cd

Browse files
committed
Fix Last Duration column to use last completed build
1 parent be95267 commit 4cff9cd

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

core/src/main/resources/hudson/views/LastDurationColumn/column.jelly

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ THE SOFTWARE.
2323
-->
2424

2525
<?jelly escape-by-default='true'?>
26-
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
27-
<j:set var="lBuild" value="${job.lastSuccessfulBuild ?: job.lastFailedBuild}"/>
28-
<td data="${lBuild.duration ?: '0'}">
26+
<j:jelly xmlns:j="jelly:core">
27+
<j:set var="lBuild" value="${job.lastCompletedBuild}"/>
28+
<td data="${lBuild.duration ?: '0'}">
2929
<j:choose>
3030
<j:when test="${lBuild!=null}">
3131
${lBuild.durationString}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package hudson.views;
2+
3+
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.Matchers.containsString;
5+
import static org.hamcrest.Matchers.not;
6+
7+
import hudson.model.FreeStyleBuild;
8+
import hudson.model.FreeStyleProject;
9+
import hudson.model.ListView;
10+
import hudson.model.Result;
11+
import org.htmlunit.html.HtmlPage;
12+
import org.jvnet.hudson.test.FailureBuilder;
13+
import org.jvnet.hudson.test.JenkinsRule;
14+
import org.jvnet.hudson.test.SleepBuilder;
15+
16+
public class LastDurationColumnTest {
17+
18+
@org.junit.Rule
19+
public JenkinsRule j = new JenkinsRule();
20+
21+
@org.junit.Test
22+
public void showsDurationOfLastCompletedBuildEvenIfFailed() throws Exception {
23+
24+
FreeStyleProject p = j.createFreeStyleProject("test-job");
25+
26+
p.getBuildersList().add(new SleepBuilder(700));
27+
FreeStyleBuild oldSuccess = j.buildAndAssertSuccess(p);
28+
29+
p.getBuildersList().clear();
30+
p.getBuildersList().add(new FailureBuilder());
31+
FreeStyleBuild newFailure = p.scheduleBuild2(0).get();
32+
j.assertBuildStatus(Result.FAILURE, newFailure);
33+
34+
String oldDuration = oldSuccess.getDurationString();
35+
String newDuration = newFailure.getDurationString();
36+
37+
ListView view = new ListView("TestView", j.jenkins);
38+
view.add(p);
39+
view.getColumns().clear();
40+
view.getColumns().add(new StatusColumn());
41+
view.getColumns().add(new JobColumn());
42+
view.getColumns().add(new LastDurationColumn());
43+
j.jenkins.addView(view);
44+
45+
HtmlPage page = j.createWebClient().getPage(view);
46+
String pageText = page.asNormalizedText();
47+
48+
assertThat("Page should show the duration of the latest build (failure)", pageText, containsString(newDuration));
49+
50+
if (!oldDuration.equals(newDuration)) {
51+
assertThat("Page should NOT show the duration of the old successful build", pageText, not(containsString(oldDuration)));
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)