/** * Allocates a workspace by adding some variation to the given base to make it unique. * * <p> * This method doesn't block prolonged amount of time. Whenever a desired workspace * is in use, the unique variation is added. */ public synchronized Lease allocate(@Nonnull FilePath base) throws InterruptedException { return allocate(base,new Object()); }
/** * Allocates a workspace by adding some variation to the given base to make it unique. * * <p> * This method doesn't block prolonged amount of time. Whenever a desired workspace * is in use, the unique variation is added. */ public synchronized Lease allocate(@Nonnull FilePath base) throws InterruptedException { return allocate(base,new Object()); }
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException { return wsl.allocate(getModuleSetBuild().getModuleRoot().child(getProject().getRelativePath())); }
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException { return wsl.allocate(getModuleSetBuild().getModuleRoot().child(getProject().getRelativePathToModuleRoot())); }
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException { return wsl.allocate(getModuleSetBuild().getModuleRoot().child(getProject().getRelativePath())); }
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException { return wsl.allocate(getModuleSetBuild().getModuleRoot().child(getProject().getRelativePathToModuleRoot())); }
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException { return wsl.allocate(getModuleSetBuild().getModuleRoot().child(getProject().getRelativePathToModuleRoot())); }
@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() {
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 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); }
protected Lease getParentWorkspaceLease(final Node n, final WorkspaceList wsl) throws InterruptedException, IOException { final DynamicProject mp = getParent().getParent(); final String customWorkspace = mp.getCustomWorkspace(); if (customWorkspace != null) { // we allow custom workspaces to be concurrently used between // jobs. return Lease.createDummyLease(n.getRootPath().child(getEnvironment(this.listener).expand(customWorkspace))); } return wsl.allocate(n.getWorkspaceFor(mp), getParentBuild()); }
throw new IllegalStateException(node + " is offline"); WorkspaceList.Lease lease = computer.getWorkspaceList().allocate(p); FilePath workspace = lease.path;
static void doRetrieve(String name, boolean changelog, @Nonnull SCM scm, FilePath target, Run<?, ?> run, TaskListener listener) throws Exception { // Adapted from CpsScmFlowDefinition: SCMStep delegate = new GenericSCMStep(scm); delegate.setPoll(false); // TODO we have no API for determining if a given SCMHead is branch-like or tag-like; would we want to turn on polling if the former? delegate.setChangelog(changelog); FilePath dir; Node node = Jenkins.getActiveInstance(); if (run.getParent() instanceof TopLevelItem) { FilePath baseWorkspace = node.getWorkspaceFor((TopLevelItem) run.getParent()); if (baseWorkspace == null) { throw new IOException(node.getDisplayName() + " may be offline"); } dir = baseWorkspace.withSuffix(getFilePathSuffix() + "libs").child(name); } else { // should not happen, but just in case: throw new AbortException("Cannot check out in non-top-level build"); } Computer computer = node.toComputer(); if (computer == null) { throw new IOException(node.getDisplayName() + " may be offline"); } try (WorkspaceList.Lease lease = computer.getWorkspaceList().allocate(dir)) { delegate.checkout(run, lease.path, listener, node.createLauncher(listener)); // Cannot add WorkspaceActionImpl to private CpsFlowExecution.flowStartNodeActions; do we care? // Copy sources with relevant files from the checkout: lease.path.copyRecursiveTo("src/**/*.groovy,vars/*.groovy,vars/*.txt,resources/", null, target); } }
return wsl.allocate(ws, getBuild());
return wsl.allocate(ws, getBuild());
@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)); } } }