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(); } }
return r; } finally { lease.release();
return r; } finally { lease.release();
return r; } finally { lease.release();
return r; } finally { lease.release();
if (spv.getName().equalsIgnoreCase("WORKSPACE_REUSE_PATH")) { return Lease.createDummyLease( new FilePath(n.getChannel(), spv.value) );
if (spv.getName().equalsIgnoreCase("WORKSPACE_REUSE_PATH")) { return Lease.createDummyLease( new FilePath(n.getChannel(), spv.value) );
@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() {
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException { // Map current combination to a directory subtree, e.g. 'axis1=a,axis2=b' to 'axis1/a/axis2/b'. String subtree; if(useShortWorkspaceName) { subtree = getParent().getDigestName(); } else { subtree = getParent().getCombination().toString('/','/', true); } String customWorkspace = getParent().getParent().getCustomWorkspace(); if (customWorkspace != null) { // Use custom workspace as defined in the matrix project settings. FilePath ws = n.getRootPath().child(getEnvironment(listener).expand(customWorkspace)); // We allow custom workspaces to be used concurrently between jobs. return Lease.createDummyLease(ws.child(subtree)); } else { // Use default workspace as assigned by Hudson. Node node = getBuiltOn(); FilePath ws = node.getWorkspaceFor(getParent().getParent()); // Allocate unique workspace (not to be shared between jobs and runs). return wsl.allocate(ws.child(subtree)); } } }
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException { // Map current combination to a directory subtree, e.g. 'axis1=a,axis2=b' to 'axis1/a/axis2/b'. String subtree; if(useShortWorkspaceName) { subtree = getParent().getDigestName(); } else { subtree = getParent().getCombination().toString('/','/', true); } String customWorkspace = getParent().getParent().getCustomWorkspace(); if (customWorkspace != null) { // Use custom workspace as defined in the matrix project settings. FilePath ws = n.getRootPath().child(getEnvironment(listener).expand(customWorkspace)); // We allow custom workspaces to be used concurrently between jobs. return Lease.createDummyLease(ws.child(subtree)); } else { // Use default workspace as assigned by Hudson. Node node = getBuiltOn(); FilePath ws = node.getWorkspaceFor(getParent().getParent()); // Allocate unique workspace (not to be shared between jobs and runs). return wsl.allocate(ws.child(subtree)); } } }
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException { // Map current combination to a directory subtree, e.g. 'axis1=a,axis2=b' to 'axis1/a/axis2/b'. String subtree; if (useShortWorkspaceName) { subtree = getParent().getDigestName(); } else { subtree = getParent().getCombination().toString('/', '/', true); } String customWorkspace = getParent().getParent().getCustomWorkspace(); if (customWorkspace != null) { // Use custom workspace as defined in the matrix project settings. FilePath ws = n.getRootPath().child(getEnvironment(listener).expand(customWorkspace)); // We allow custom workspaces to be used concurrently between jobs. return Lease.createDummyLease(ws.child(subtree)); } else { // Use default workspace as assigned by Hudson. Node node = getBuiltOn(); FilePath ws = node.getWorkspaceFor(getParent().getParent()); // Allocate unique workspace (not to be shared between jobs and runs). return wsl.allocate(ws.child(subtree)); } } }
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException { // Map current combination to a directory subtree, e.g. 'axis1=a,axis2=b' to 'axis1/a/axis2/b'. String subtree; if(useShortWorkspaceName) { subtree = getParent().getDigestName(); } else { subtree = getParent().getCombination().toString('/','/', true); } String customWorkspace = getParent().getParent().getCustomWorkspace(); if (customWorkspace != null) { // Use custom workspace as defined in the matrix project settings. FilePath ws = n.getRootPath().child(getEnvironment(listener).expand(customWorkspace)); // We allow custom workspaces to be used concurrently between jobs. return Lease.createDummyLease(ws.child(subtree)); } else { // Use default workspace as assigned by Hudson. Node node = getBuiltOn(); FilePath ws = node.getWorkspaceFor(getParent().getParent()); // Allocate unique workspace (not to be shared between jobs and runs). return wsl.allocate(ws.child(subtree)); } } }
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException { MatrixProject mp = getParent().getParent(); // lock is done at the parent level, so that concurrent MatrixProjects get respective workspace, // but within MatrixConfigurations that belong to the same MatrixBuild. // if MatrixProject is configured with custom workspace, we assume that the user knows what he's doing // and try not to append unique random suffix. Lease baseLease = getParentWorkspaceLease(n,wsl); // resolve the relative path against the parent workspace, which needs locking FilePath baseDir = baseLease.path; // prepare variables that can be used in the child workspace setting EnvVars env = getEnvironment(listener); env.put("COMBINATION",getParent().getCombination().toString('/','/')); // e.g., "axis1/a/axis2/b" env.put("SHORT_COMBINATION",getParent().getDigestName()); // e.g., "0fbcab35" env.put("PARENT_WORKSPACE",baseDir.getRemote()); env.putAll(getBuildVariables()); // child workspace need no individual locks, whether or not we use custom workspace String childWs = mp.getChildCustomWorkspace(); return Lease.createLinkedDummyLease(baseDir.child(env.expand(childWs)),baseLease); } }
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException { if (getTarget() == null) { throw new IOException("No Promotion target, cannot retrieve workspace"); } String customWorkspace = Promotion.this.getProject().getCustomWorkspace(); if (customWorkspace != null) { final FilePath rootPath = n.getRootPath(); if (rootPath == null) { throw new IOException("Cannot retrieve the root path of the node " + n); } // we allow custom workspaces to be concurrently used between jobs. return Lease.createDummyLease( rootPath.child(getEnvironment(listener).expand(customWorkspace))); } TopLevelItem item = (TopLevelItem)getTarget().getProject(); FilePath workspace = n.getWorkspaceFor(item); if (workspace == null) { throw new IOException("Cannot retrieve workspace for " + item + " on the node " + n); } return wsl.allocate(workspace, promotionRun); }
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(); } }
protected Lease getParentWorkspaceLease(Node n, WorkspaceList wsl) throws InterruptedException, IOException { MatrixProject mp = getParent().getParent(); String customWorkspace = mp.getCustomWorkspace(); if (customWorkspace != null) { final FilePath nodeRoot = n.getRootPath(); if (nodeRoot == null) { throw new IOException("Cannot retrieve the node's root. Most probably it's offline"); } // we allow custom workspaces to be concurrently used between jobs. return Lease.createDummyLease(nodeRoot.child(getEnvironment(listener).expand(customWorkspace))); } final FilePath workspace = n.getWorkspaceFor(mp); if (workspace == null) { throw new IOException("Cannot retrieve the node's workspace for " + mp + ". Most probably the node is offline"); } return wsl.allocate(workspace, getParentBuild()); }
@Override public void onFailure(StepContext context, Throwable t) { lease.release(); this.context.onFailure(t); } }
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws IOException, InterruptedException { String customWorkspace = getProject().getCustomWorkspace(); if (customWorkspace != null) // we allow custom workspaces to be concurrently used between jobs. return Lease.createDummyLease(n.getRootPath().child(getEnvironment(listener).expand(customWorkspace))); return super.decideWorkspace(n,wsl); } }
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws IOException, InterruptedException { String customWorkspace = getProject().getCustomWorkspace(); if (customWorkspace != null) { // we allow custom workspaces to be concurrently used between jobs. return Lease.createDummyLease(n.getRootPath().child(getEnvironment(listener).expand(customWorkspace))); } return super.decideWorkspace(n, wsl); }