提交 e65f893b 编写于 作者: C Christoph Kutzinski 提交者: Kohsuke Kawaguchi

[JENKINS-8848] allow custom workspaces for maven jobs

上级 1f8ac362
......@@ -323,17 +323,6 @@ public class MatrixBuild extends AbstractBuild<MatrixProject,MatrixBuild> {
for (MatrixAggregator a : aggregators)
a.endBuild();
}
@Override
protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws IOException, InterruptedException {
String customWorkspace = getProject().getCustomWorkspace();
if (customWorkspace != null) {
// we allow custom workspaces to be concurrently used between jobs.
return Lease.createDummyLease(n.getRootPath().child(getEnvironment(listener).expand(customWorkspace)));
}
return super.decideWorkspace(n,wsl);
}
}
/**
......
......@@ -143,11 +143,6 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
*/
private Result touchStoneResultCondition;
/**
* See {@link #setCustomWorkspace(String)}.
*/
private String customWorkspace;
public MatrixProject(String name) {
this(Hudson.getInstance(), name);
}
......@@ -229,28 +224,6 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
this.touchStoneResultCondition = touchStoneResultCondition;
}
public String getCustomWorkspace() {
return customWorkspace;
}
/**
* User-specified workspace directory, or null if it's up to Hudson.
*
* <p>
* Normally a matrix project uses the workspace location assigned by its parent container,
* but sometimes people have builds that have hard-coded paths.
*
* <p>
* This is not {@link File} because it may have to hold a path representation on another OS.
*
* <p>
* If this path is relative, it's resolved against {@link Node#getRootPath()} on the node where this workspace
* is prepared.
*/
public void setCustomWorkspace(String customWorkspace) throws IOException {
this.customWorkspace= customWorkspace;
}
@Override
protected List<Action> createTransientActions() {
List<Action> r = super.createTransientActions();
......@@ -594,12 +567,6 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
this.touchStoneCombinationFilter = null;
}
if(req.hasParameter("customWorkspace")) {
customWorkspace = req.getParameter("customWorkspace.directory");
} else {
customWorkspace = null;
}
// parse system axes
DescribableList<Axis,AxisDescriptor> newAxes = new DescribableList<Axis,AxisDescriptor>(this);
newAxes.rebuildHetero(req, json, Axis.all(),"axis");
......
......@@ -394,6 +394,11 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
* Passed in for the convenience. The returned path must be registered to this object.
*/
protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException {
String customWorkspace = getProject().getCustomWorkspace();
if (customWorkspace != null) {
// we allow custom workspaces to be concurrently used between jobs.
return Lease.createDummyLease(n.getRootPath().child(getEnvironment(listener).expand(customWorkspace)));
}
// TODO: this cast is indicative of abstraction problem
return wsl.allocate(n.getWorkspaceFor((TopLevelItem)getProject()));
}
......
......@@ -219,6 +219,13 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
private boolean concurrentBuild;
/**
* See {@link #setCustomWorkspace(String)}.
*
* @since xxx
*/
private String customWorkspace;
protected AbstractProject(ItemGroup parent, String name) {
super(parent,name);
......@@ -1629,6 +1636,12 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
blockBuildWhenDownstreamBuilding = req.getParameter("blockBuildWhenDownstreamBuilding")!=null;
blockBuildWhenUpstreamBuilding = req.getParameter("blockBuildWhenUpstreamBuilding")!=null;
if(req.hasParameter("customWorkspace")) {
customWorkspace = req.getParameter("customWorkspace.directory");
} else {
customWorkspace = null;
}
if(req.getParameter("hasSlaveAffinity")!=null) {
assignedNode = Util.fixEmptyAndTrim(req.getParameter("_.assignedLabelString"));
} else {
......@@ -1942,4 +1955,29 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
throw new CmdLineException(null,Messages.AbstractItem_NoSuchJobExists(name,AbstractProject.findNearest(name).getFullName()));
return item;
}
public String getCustomWorkspace() {
return customWorkspace;
}
/**
* User-specified workspace directory, or null if it's up to Jenkins.
*
* <p>
* Normally a project uses the workspace location assigned by its parent container,
* but sometimes people have builds that have hard-coded paths.
*
* <p>
* This is not {@link File} because it may have to hold a path representation on another OS.
*
* <p>
* If this path is relative, it's resolved against {@link Node#getRootPath()} on the node where this workspace
* is prepared.
*
* @since XXX
*/
public void setCustomWorkspace(String customWorkspace) throws IOException {
this.customWorkspace= customWorkspace;
save();
}
}
......@@ -45,15 +45,4 @@ public class FreeStyleBuild extends Build<FreeStyleProject,FreeStyleBuild> {
public void run() {
run(new RunnerImpl());
}
protected class RunnerImpl extends Build<FreeStyleProject,FreeStyleBuild>.RunnerImpl {
@Override
protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws IOException, InterruptedException {
String customWorkspace = getProject().getCustomWorkspace();
if (customWorkspace != null)
// we allow custom workspaces to be concurrently used between jobs.
return Lease.createDummyLease(n.getRootPath().child(getEnvironment(listener).expand(customWorkspace)));
return super.decideWorkspace(n,wsl);
}
}
}
......@@ -39,12 +39,6 @@ import javax.servlet.ServletException;
* @author Kohsuke Kawaguchi
*/
public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> implements TopLevelItem {
/**
* See {@link #setCustomWorkspace(String)}.
*
* @since 1.216
*/
private String customWorkspace;
/**
* @deprecated as of 1.390
......@@ -62,43 +56,6 @@ public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> i
return FreeStyleBuild.class;
}
public String getCustomWorkspace() {
return customWorkspace;
}
/**
* 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.
*
* <p>
* If this path is relative, it's resolved against {@link Node#getRootPath()} on the node where this workspace
* is prepared.
*
* @since 1.320
*/
public void setCustomWorkspace(String customWorkspace) throws IOException {
this.customWorkspace= customWorkspace;
save();
}
@Override
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;
}
......
......@@ -93,6 +93,7 @@ THE SOFTWARE.
checked="${it.isResolveDependencies()}" />
<f:optionalBlock name="maven.processPlugins" title="${%Process Plugins during Pom parsing}"
checked="${it.isProcessPlugins()}" />
<p:config-customWorkspace />
<j:set var="mavenValidationLevels" value="${it.descriptor.mavenValidationLevels}" />
<f:entry title="${%Maven Validation Level}">
......
......@@ -6,11 +6,10 @@
<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
Another situation where this is useful is when you are using the 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 Jenkins web UI, and you can kick relevant commands more easily.
......
......@@ -7,12 +7,11 @@
<p>
In einer solchen Situation verwenden Sie beispielsweise "festverdrahtete" Dateipfade und
der Code muß daher an einer bestimmten Stelle im Dateisystem gebaut werden
(<a href="http://www.nabble.com/Customize-Workspace-directory-tt17194310.html">mehr dazu</a>).
der Code muß daher an einer bestimmten Stelle im Dateisystem gebaut werden.
Zweifellos ist dies kein Idealfall eines Builds, aber diese Option erlaubt es Ihnen,
auch in einer solchen Situation weiterzukommmen.
<p>
In einer anderen Situation verwenden Sie ein "Free-Style"-Projekt nicht um einen
In einer anderen Situation verwenden Sie ein Projekt nicht um einen
Software-Build auszuführen, sondern um eine Batch-Aufgabe auszuführen, z.B. als Cron-Ersatz.
In diesem Fall können Sie diese Option verwenden, um ein relevantes Verzeichnis als
Arbeitsverzeichnis einzustellen, so daß Anwender Dateien in diesem Verzeichnis über
......
......@@ -7,8 +7,7 @@
<p>
Un exemple d'une telle situation est quand les chemins sont codés en dur et que le code a besoin
d'être construit à partir d'un emplacement spécifique (voir la discussion
<a href="http://www.nabble.com/Customize-Workspace-directory-tt17194310.html">ici</a>).
d'être construit à partir d'un emplacement spécifique.
Il est certain qu'une telle configuration de build est déconseillée, mais cette option vous
permet néanmoins d'avencer dans ces circonstances.
......
......@@ -6,11 +6,10 @@
<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
Another situation where this is useful is when you are using the 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 Jenkins web UI, and you can kick relevant commands more easily.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册