private PollingResult pollWithWorkspace(TaskListener listener, SCM scm, R lb, @Nonnull FilePath ws, WorkspaceList l) throws InterruptedException, IOException { // if doing non-concurrent build, acquire a workspace in a way that causes builds to block for this workspace. // this prevents multiple workspaces of the same job --- the behavior of Hudson < 1.319. // // OTOH, if a concurrent build is chosen, the user is willing to create a multiple workspace, // so better throughput is achieved over time (modulo the initial cost of creating that many workspaces) // by having multiple workspaces Node node = lb.getBuiltOn(); Launcher launcher = ws.createLauncher(listener).decorateByEnv(getEnvironment(node,listener)); WorkspaceList.Lease lease = l.acquire(ws, !concurrentBuild); try { String nodeName = node != null ? node.getSelfLabel().getName() : "[node_unavailable]"; listener.getLogger().println("Polling SCM changes on " + nodeName); LOGGER.fine("Polling SCM changes of " + getName()); if (pollingBaseline==null) // see NOTE-NO-BASELINE above calcPollingBaseline(lb,launcher,listener); PollingResult r = scm.poll(this, launcher, ws, listener, pollingBaseline); pollingBaseline = r.remote; return r; } finally { lease.release(); } }
@Override protected void finished(StepContext context) throws Exception { LOGGER.log(FINE, "finished {0}", cookie); lease.release(); lease = null; finish(cookie); }
@Override protected void finished(StepContext context) throws Exception { LOGGER.log(FINE, "finished {0}", cookie); lease.release(); lease = null; finish(cookie); }
return r; } finally { lease.release();
return r; } finally { lease.release();
return r; } finally { lease.release();
return r; } finally { lease.release();
@SuppressFBWarnings(value="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification="TODO 1.653+ switch to Jenkins.getInstanceOrNull") @Override protected WorkspaceList.Lease tryResolve() throws InterruptedException { Jenkins j = Jenkins.getInstance(); if (j == null) { return null; } // FilePathUtils.find not useful here since we need c anyway, and cannot easily return a tuple // (could call toComputer on result but then we iterate computers twice, a possible race condition) Computer c = j.getComputer(slave); if (c == null) { return null; } VirtualChannel ch = c.getChannel(); if (ch == null) { return null; } FilePath fp = new FilePath(ch, path); // Since there is no equivalent to Lock.tryLock for WorkspaceList (.record would work but throws AssertionError and swaps the holder): WorkspaceList.Lease lease = c.getWorkspaceList().allocate(fp); if (lease.path.equals(fp)) { return lease; } else { // @2 or other variant, not what we expected to be able to lock without contention lease.release(); throw new IllegalStateException("JENKINS-37121: something already locked " + fp); } } @Override public String toString() {
private PollingResult pollWithWorkspace(TaskListener listener, SCM scm, R lb, @Nonnull FilePath ws, WorkspaceList l) throws InterruptedException, IOException { // if doing non-concurrent build, acquire a workspace in a way that causes builds to block for this workspace. // this prevents multiple workspaces of the same job --- the behavior of Hudson < 1.319. // // OTOH, if a concurrent build is chosen, the user is willing to create a multiple workspace, // so better throughput is achieved over time (modulo the initial cost of creating that many workspaces) // by having multiple workspaces Node node = lb.getBuiltOn(); Launcher launcher = ws.createLauncher(listener).decorateByEnv(getEnvironment(node,listener)); WorkspaceList.Lease lease = l.acquire(ws, !concurrentBuild); try { String nodeName = node != null ? node.getSelfLabel().getName() : "[node_unavailable]"; listener.getLogger().println("Polling SCM changes on " + nodeName); LOGGER.fine("Polling SCM changes of " + getName()); if (pollingBaseline==null) // see NOTE-NO-BASELINE above calcPollingBaseline(lb,launcher,listener); PollingResult r = scm.poll(this, launcher, ws, listener, pollingBaseline); pollingBaseline = r.remote; return r; } finally { lease.release(); } }
@Override public void onFailure(StepContext context, Throwable t) { lease.release(); this.context.onFailure(t); } }
@Override protected void finished(StepContext context) throws Exception { LOGGER.log(FINE, "finished {0}", cookie); lease.release(); lease = null; finish(cookie); }
/** * By default, calls {@link #release}, but should be idempotent. * @since 1.600 */ @Override public void close() { release(); }
public void release() { parent.release(); } };
@Override protected void finished(StepContext context) throws Exception { lease.release(); }
@Override public void onSuccess(StepContext context, Object result) { lease.release(); this.context.onSuccess(result); }
public void release() { parent.release(); } };
/** * By default, calls {@link #release}, but should be idempotent. * @since 1.600 */ @Override public void close() { release(); }