Skip to content
Permalink
Browse files

[FIXED JENKINS-16023] Use permalinks for as many Job.getLast*Build me…

…thods as possible.
  • Loading branch information
jglick committed May 30, 2013
1 parent 2b0bd97 commit be5cd4fd169005f50eea8ccefac4b91a9b4c503c
Showing with 31 additions and 21 deletions.
  1. +3 −0 changelog.html
  2. +4 −21 core/src/main/java/hudson/model/Job.java
  3. +24 −0 test/src/test/java/hudson/model/JobTest.java
@@ -64,6 +64,9 @@
<li class='major bug'>
Errors searching build records when builds were misordered.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-15652">issue 15652</a>)
<li class='major bug'>
Finding the last failed build for a job (e.g. from a view column) broke lazy loading.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-16023">issue 16023</a>)
<li class=bug>
Do not fail startup in case <code>ListView.includeRegex</code> was syntactically malformed.
<li class=bug>
@@ -26,7 +26,6 @@
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import hudson.BulkChange;
import hudson.EnvVars;
import hudson.Extension;
import hudson.ExtensionPoint;
@@ -64,7 +63,6 @@
import jenkins.model.BuildDiscarder;
import jenkins.model.Jenkins;
import jenkins.model.ProjectNamingStrategy;
import jenkins.scm.SCMCheckoutStrategy;
import jenkins.security.HexStringConfidentialKey;
import jenkins.util.io.OnMaster;
import net.sf.json.JSONException;
@@ -809,11 +807,7 @@ public RunT getLastSuccessfulBuild() {
@Exported
@QuickSilver
public RunT getLastUnsuccessfulBuild() {
RunT r = getLastBuild();
while (r != null
&& (r.isBuilding() || r.getResult() == Result.SUCCESS))
r = r.getPreviousBuild();
return r;
return (RunT)Permalink.LAST_UNSUCCESSFUL_BUILD.resolve(this);
}

/**
@@ -823,11 +817,7 @@ public RunT getLastUnsuccessfulBuild() {
@Exported
@QuickSilver
public RunT getLastUnstableBuild() {
RunT r = getLastBuild();
while (r != null
&& (r.isBuilding() || r.getResult() != Result.UNSTABLE))
r = r.getPreviousBuild();
return r;
return (RunT)Permalink.LAST_UNSTABLE_BUILD.resolve(this);
}

/**
@@ -837,11 +827,7 @@ public RunT getLastUnstableBuild() {
@Exported
@QuickSilver
public RunT getLastStableBuild() {
RunT r = getLastBuild();
while (r != null
&& (r.isBuilding() || r.getResult().isWorseThan(Result.SUCCESS)))
r = r.getPreviousBuild();
return r;
return (RunT)Permalink.LAST_STABLE_BUILD.resolve(this);
}

/**
@@ -850,10 +836,7 @@ public RunT getLastStableBuild() {
@Exported
@QuickSilver
public RunT getLastFailedBuild() {
RunT r = getLastBuild();
while (r != null && (r.isBuilding() || r.getResult() != Result.FAILURE))
r = r.getPreviousBuild();
return r;
return (RunT)Permalink.LAST_FAILED_BUILD.resolve(this);
}

/**
@@ -31,6 +31,7 @@
import hudson.util.TextFile;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;

import jenkins.model.ProjectNamingStrategy;
@@ -39,7 +40,9 @@
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.FailureBuilder;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.RunLoadCounter;
import org.jvnet.hudson.test.recipes.LocalData;

/**
@@ -253,4 +256,25 @@ private static void tryConfigDotXml(JenkinsRule.WebClient wc, int status, String
}
j.createFreeStyleProject("project");
}

@Bug(16023)
@Test public void getLastFailedBuild() throws Exception {
final FreeStyleProject p = j.createFreeStyleProject();
RunLoadCounter.prepare(p);
p.getBuildersList().add(new FailureBuilder());
j.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get());
j.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get());
j.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get());
p.getBuildersList().remove(FailureBuilder.class);
j.assertBuildStatusSuccess(p.scheduleBuild2(0));
j.assertBuildStatusSuccess(p.scheduleBuild2(0));
j.assertBuildStatusSuccess(p.scheduleBuild2(0));
assertEquals(6, p.getLastSuccessfulBuild().getNumber());
assertEquals(3, RunLoadCounter.assertMaxLoads(p, 1, new Callable<Integer>() {
@Override public Integer call() throws Exception {
return p.getLastFailedBuild().getNumber();
}
}).intValue());
}

}

1 comment on commit be5cd4f

@gcummings

This comment has been minimized.

Copy link
Contributor

@gcummings gcummings commented on be5cd4f Dec 17, 2013

Hi Jesse,

If you have time could you please give some feedback on JENKINS-20989 which is related to this change.

It's good to use the Permalinks but I think we may need to update the Permalinks slightly sooner in the Run#execute flow so they are updated prior to triggering downstream builds.

many thanks
Geoff

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