mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-18 06:22:29 +00:00
Allowed workspace directory to be customized.
See http://www.nabble.com/Customize-Workspace-directory-tt17194310.html git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@9330 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
948b6c0c33
commit
47d481f88d
6 files changed
+86
-1
No files matched your search
@@ -2,12 +2,35 @@ package hudson.model;
|
||||
|
||||
import hudson.FilePath;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
/**
|
||||
* Free-style software project.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> implements TopLevelItem {
|
||||
/**
|
||||
* User-specified workspace directory, or null if it's up to Hudson.
|
||||
*
|
||||
* <p>
|
||||
* Normally a free-style project uses the workspace location assigned by its parent container,
|
||||
* but sometimes people have builds that have hard-coded paths (which can be only built in
|
||||
* certain locations. see http://www.nabble.com/Customize-Workspace-directory-tt17194310.html for
|
||||
* one such discussion.)
|
||||
*
|
||||
* <p>
|
||||
* This is not {@link File} because it may have to hold a path representation on another OS.
|
||||
*
|
||||
* @since 1.216
|
||||
*/
|
||||
private String customWorkspace;
|
||||
|
||||
public FreeStyleProject(Hudson parent, String name) {
|
||||
super(parent, name);
|
||||
@@ -23,13 +46,28 @@ public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> i
|
||||
return Hudson.getInstance();
|
||||
}
|
||||
|
||||
public String getCustomWorkspace() {
|
||||
return customWorkspace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilePath getWorkspace() {
|
||||
Node node = getLastBuiltOn();
|
||||
if(node==null) node = getParent();
|
||||
if(customWorkspace!=null)
|
||||
return node.createPath(customWorkspace);
|
||||
return node.getWorkspaceFor(this);
|
||||
}
|
||||
|
||||
protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, Descriptor.FormException {
|
||||
if(req.hasParameter("customWorkspace"))
|
||||
customWorkspace = req.getParameter("customWorkspace.directory");
|
||||
else
|
||||
customWorkspace = null;
|
||||
|
||||
super.submit(req, rsp);
|
||||
}
|
||||
|
||||
public DescriptorImpl getDescriptor() {
|
||||
return DESCRIPTOR;
|
||||
}
|
||||
|
||||
@@ -935,6 +935,10 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
|
||||
return new FilePath(getRootDir());
|
||||
}
|
||||
|
||||
public FilePath createPath(String absolutePath) {
|
||||
return new FilePath((VirtualChannel)null,absolutePath);
|
||||
}
|
||||
|
||||
public ClockDifference getClockDifference() {
|
||||
return ClockDifference.ZERO;
|
||||
}
|
||||
|
||||
@@ -106,6 +106,11 @@ public interface Node {
|
||||
*/
|
||||
FilePath getRootPath();
|
||||
|
||||
/**
|
||||
* Gets the {@link FilePath} on this node.
|
||||
*/
|
||||
FilePath createPath(String absolutePath);
|
||||
|
||||
/**
|
||||
* Estimates the clock difference with this slave.
|
||||
*
|
||||
|
||||
@@ -311,9 +311,13 @@ public final class Slave implements Node, Serializable {
|
||||
}
|
||||
|
||||
public FilePath getRootPath() {
|
||||
return createPath(remoteFS);
|
||||
}
|
||||
|
||||
public FilePath createPath(String absolutePath) {
|
||||
VirtualChannel ch = getComputer().getChannel();
|
||||
if(ch==null) return null; // offline
|
||||
return new FilePath(ch,remoteFS);
|
||||
return new FilePath(ch,absolutePath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user