提交 47d481f8 编写于 作者: K kohsuke

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
上级 948b6c0c
......@@ -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);
}
/**
......
<!--
Additional entries in the advanced section.
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:p="/lib/hudson/project">
<f:optionalBlock name="customWorkspace" title="${%Use custom workspace}" checked="${it.customWorkspace!=null}"
help="/help/project-config/custom-workspace.html">
<f:entry title="${%Directory}">
<f:textbox name="customWorkspace.directory" value="${it.customWorkspace}" />
</f:entry>
</f:optionalBlock>
</j:jelly>
\ No newline at end of file
<div>
For each job on Hudson, Hudson allocates a unique "workspace directory." This is the directory
where the code is checked out and builds happen. Normally you should let Hudson allocate
and clean up workspace directories, but in several situations this is problematic,
and in such case, this option lets you specify the workspace location manually.
<p>
Once such situation is where paths are hard-coded and the code needs to be built on a specific location.
(and you can find one such discussion <a href="http://www.nabble.com/Customize-Workspace-directory-tt17194310.html">here</a>.)
While there's no doubt that such a build is not ideal, this option allows you to get going in such a situation.
<p>
Another situation where this is useful is when you are using the free-style project type not to perform
a software build, but execution of a certain batch task, perhaps as a cron replacement. In such case,
you can use this option to map the relevant directory as the workspace, so that people can look at files
through the Hudson web UI, and you can kick relevant commands more easily.
<p>
If you are in a distributed build environment, unless you tie a job to a specific node, Hudson may still
move around jobs to different slaves. Sometimes this is desirable, sometimes this is not. Also,
you can map multiple projects to have the same workspace, but if you do so, make sure concurrent executions
of those jobs won't have nasty interferance with each other.
</div>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册