@Override public MatrixProject decorate(MatrixProject project) { if (!isProject(project)) { return project; } if (!(getOwner() instanceof MatrixMultiBranchProject)) { throw new IllegalStateException(String.format("%s can only be used with %s.", MatrixBranchProjectFactory.class.getSimpleName(), MatrixMultiBranchProject.class.getSimpleName())); } MatrixMultiBranchProject owner = (MatrixMultiBranchProject) getOwner(); BulkChange bc = new BulkChange(project); try { project = super.decorate(project); // Workaround for JENKINS-21017 if (owner.getTemplate().hasChildCustomWorkspace()) { project.setChildCustomWorkspace(owner.getTemplate().getChildCustomWorkspace()); } else { project.setChildCustomWorkspace(null); } bc.commit(); } catch (IOException e) { LOGGER.log(Level.WARNING, "Unable to update project " + project.getName(), e); } finally { bc.abort(); } return project; }
@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); } }