mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 05:22:22 +00:00
Merge pull request #690 from recampbell/workspace-customization
Introduce jenkins.slaves.WorkspaceLocator Thanks !
This commit is contained in:
commit
c3d9b844d8
3 files changed
+55
No files matched your search
@@ -58,6 +58,8 @@ import java.util.Set;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import jenkins.model.Jenkins;
|
||||
import jenkins.slaves.WorkspaceLocator;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
import org.kohsuke.stapler.HttpResponse;
|
||||
@@ -267,6 +269,13 @@ public abstract class Slave extends Node implements Serializable {
|
||||
}
|
||||
|
||||
public FilePath getWorkspaceFor(TopLevelItem item) {
|
||||
for (WorkspaceLocator l : WorkspaceLocator.all()) {
|
||||
FilePath workspace = l.locate(item, this);
|
||||
if (workspace != null) {
|
||||
return workspace;
|
||||
}
|
||||
}
|
||||
|
||||
FilePath r = getWorkspaceRoot();
|
||||
if(r==null) return null; // offline
|
||||
return r.child(item.getFullName());
|
||||
|
||||
@@ -197,6 +197,7 @@ import jenkins.InitReactorRunner;
|
||||
import jenkins.model.ProjectNamingStrategy.DefaultProjectNamingStrategy;
|
||||
import jenkins.security.ConfidentialKey;
|
||||
import jenkins.security.ConfidentialStore;
|
||||
import jenkins.slaves.WorkspaceLocator;
|
||||
import jenkins.util.io.FileBoolean;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.acegisecurity.AccessDeniedException;
|
||||
@@ -1925,6 +1926,13 @@ public class Jenkins extends AbstractCIBase implements ModifiableTopLevelItemGro
|
||||
}
|
||||
|
||||
public FilePath getWorkspaceFor(TopLevelItem item) {
|
||||
for (WorkspaceLocator l : WorkspaceLocator.all()) {
|
||||
FilePath workspace = l.locate(item, this);
|
||||
if (workspace != null) {
|
||||
return workspace;
|
||||
}
|
||||
}
|
||||
|
||||
return new FilePath(expandVariablesForDirectory(workspaceDir, item));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package jenkins.slaves;
|
||||
|
||||
import hudson.ExtensionList;
|
||||
import hudson.ExtensionPoint;
|
||||
import hudson.FilePath;
|
||||
import hudson.model.Node;
|
||||
import hudson.model.TopLevelItem;
|
||||
import jenkins.model.Jenkins;
|
||||
|
||||
/**
|
||||
* Allow extensions to override workspace locations
|
||||
* on given slaves or projects.
|
||||
*
|
||||
* @author ryan.campbell@gmail.com
|
||||
* @since 1.501
|
||||
*/
|
||||
public abstract class WorkspaceLocator implements ExtensionPoint {
|
||||
|
||||
/**
|
||||
* Allows extensions to customize the workspace path. The first non-null response
|
||||
* will determine the path to the workspace on that slave.
|
||||
*
|
||||
* @param item The toplevel item
|
||||
* @param slave The slave
|
||||
* @return The absolute FilePath to the workspace on the slave.
|
||||
* Will be created if it doesn't exist.
|
||||
*
|
||||
*/
|
||||
public abstract FilePath locate(TopLevelItem item, Node node);
|
||||
|
||||
|
||||
/**
|
||||
* All registered {@link WorkspaceLocator}s.
|
||||
*/
|
||||
public static ExtensionList<WorkspaceLocator> all() {
|
||||
return Jenkins.getInstance().getExtensionList(WorkspaceLocator.class);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user