提交 84388823 编写于 作者: K Kohsuke Kawaguchi

Merge pull request #849 from Vlatombe/polling-should-look-at-older-builds

Poll on the last existing workspace instead of the last workspace,
...@@ -569,6 +569,15 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A ...@@ -569,6 +569,15 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
} }
return null; return null;
} }
private R getSomeBuildWithExistingWorkspace() throws IOException, InterruptedException {
int cnt=0;
for (R b = getLastBuild(); cnt<5 && b!=null; b=b.getPreviousBuild()) {
FilePath ws = b.getWorkspace();
if (ws!=null && ws.exists()) return b;
}
return null;
}
/** /**
* Returns the root directory of the checked-out module. * Returns the root directory of the checked-out module.
...@@ -1470,7 +1479,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A ...@@ -1470,7 +1479,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
try { try {
SCMPollListener.fireBeforePolling(this, listener); SCMPollListener.fireBeforePolling(this, listener);
PollingResult r = _poll(listener, scm, lb); PollingResult r = _poll(listener, scm);
SCMPollListener.firePollingSuccess(this,listener, r); SCMPollListener.firePollingSuccess(this,listener, r);
return r; return r;
} catch (AbortException e) { } catch (AbortException e) {
...@@ -1499,18 +1508,20 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A ...@@ -1499,18 +1508,20 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
/** /**
* {@link #poll(TaskListener)} method without the try/catch block that does listener notification and . * {@link #poll(TaskListener)} method without the try/catch block that does listener notification and .
*/ */
private PollingResult _poll(TaskListener listener, SCM scm, R lb) throws IOException, InterruptedException { private PollingResult _poll(TaskListener listener, SCM scm) throws IOException, InterruptedException {
if (scm.requiresWorkspaceForPolling()) { if (scm.requiresWorkspaceForPolling()) {
// lock the workspace of the last build R b = getSomeBuildWithExistingWorkspace();
FilePath ws=lb.getWorkspace(); if (b == null) b = getLastBuild();
// lock the workspace for the given build
FilePath ws=b.getWorkspace();
WorkspaceOfflineReason workspaceOfflineReason = workspaceOffline( lb ); WorkspaceOfflineReason workspaceOfflineReason = workspaceOffline( b );
if ( workspaceOfflineReason != null ) { if ( workspaceOfflineReason != null ) {
// workspace offline // workspace offline
for (WorkspaceBrowser browser : Jenkins.getInstance().getExtensionList(WorkspaceBrowser.class)) { for (WorkspaceBrowser browser : Jenkins.getInstance().getExtensionList(WorkspaceBrowser.class)) {
ws = browser.getWorkspace(this); ws = browser.getWorkspace(this);
if (ws != null) { if (ws != null) {
return pollWithWorkspace(listener, scm, lb, ws, browser.getWorkspaceList()); return pollWithWorkspace(listener, scm, b, ws, browser.getWorkspaceList());
} }
} }
...@@ -1535,8 +1546,8 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A ...@@ -1535,8 +1546,8 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
return BUILD_NOW; return BUILD_NOW;
} }
} else { } else {
WorkspaceList l = lb.getBuiltOn().toComputer().getWorkspaceList(); WorkspaceList l = b.getBuiltOn().toComputer().getWorkspaceList();
return pollWithWorkspace(listener, scm, lb, ws, l); return pollWithWorkspace(listener, scm, b, ws, l);
} }
} else { } else {
...@@ -1544,7 +1555,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A ...@@ -1544,7 +1555,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
LOGGER.fine("Polling SCM changes of " + getName()); LOGGER.fine("Polling SCM changes of " + getName());
if (pollingBaseline==null) // see NOTE-NO-BASELINE above if (pollingBaseline==null) // see NOTE-NO-BASELINE above
calcPollingBaseline(lb,null,listener); calcPollingBaseline(getLastBuild(),null,listener);
PollingResult r = scm.poll(this, null, null, listener, pollingBaseline); PollingResult r = scm.poll(this, null, null, listener, pollingBaseline);
pollingBaseline = r.remote; pollingBaseline = r.remote;
return r; return r;
...@@ -1559,8 +1570,10 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A ...@@ -1559,8 +1570,10 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
// so better throughput is achieved over time (modulo the initial cost of creating that many workspaces) // so better throughput is achieved over time (modulo the initial cost of creating that many workspaces)
// by having multiple workspaces // by having multiple workspaces
WorkspaceList.Lease lease = l.acquire(ws, !concurrentBuild); WorkspaceList.Lease lease = l.acquire(ws, !concurrentBuild);
Launcher launcher = ws.createLauncher(listener).decorateByEnv(getEnvironment(lb.getBuiltOn(),listener)); Node node = lb.getBuiltOn();
Launcher launcher = ws.createLauncher(listener).decorateByEnv(getEnvironment(node,listener));
try { try {
listener.getLogger().println("Polling SCM changes on " + node.getSelfLabel().getName());
LOGGER.fine("Polling SCM changes of " + getName()); LOGGER.fine("Polling SCM changes of " + getName());
if (pollingBaseline==null) // see NOTE-NO-BASELINE above if (pollingBaseline==null) // see NOTE-NO-BASELINE above
calcPollingBaseline(lb,launcher,listener); calcPollingBaseline(lb,launcher,listener);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册