提交 00c2c656 编写于 作者: S swiest

[FIXED HUDSON-5077] Added support for custom workspaces in matrix projects.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@34732 71c3de6d-444a-0410-be80-ed276b4c234a
上级 7e684654
......@@ -31,10 +31,13 @@ import hudson.model.Executor;
import hudson.model.Fingerprint;
import hudson.model.Hudson;
import hudson.model.JobProperty;
import hudson.model.Node;
import hudson.model.ParametersAction;
import hudson.model.Queue;
import hudson.model.Result;
import hudson.model.Cause.UpstreamCause;
import hudson.slaves.WorkspaceList;
import hudson.slaves.WorkspaceList.Lease;
import hudson.tasks.Publisher;
import java.io.File;
......@@ -320,6 +323,17 @@ 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);
}
}
/**
......
......@@ -141,6 +141,11 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
*/
private Result touchStoneResultCondition;
/**
* See {@link #setCustomWorkspace(String)}.
*/
private String customWorkspace;
public MatrixProject(String name) {
super(Hudson.getInstance(), name);
}
......@@ -218,6 +223,28 @@ 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 void updateTransientActions() {
synchronized(transientActions) {
......@@ -558,6 +585,12 @@ 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");
......
......@@ -140,12 +140,27 @@ public class MatrixRun extends Build<MatrixConfiguration,MatrixRun> {
protected class RunnerImpl extends Build<MatrixConfiguration,MatrixRun>.RunnerImpl {
@Override
protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException {
Node node = getBuiltOn();
FilePath ws = node.getWorkspaceFor(getParent().getParent());
if(useShortWorkspaceName)
return wsl.allocate(ws.child(getParent().getDigestName()));
else
return wsl.allocate(ws.child(getParent().getCombination().toString('/','/')));
// Map current combination to a directory subtree, e.g. 'axis1=a,axis2=b' to 'axis1/a/axis2/b'.
String subtree;
if(useShortWorkspaceName) {
subtree = getParent().getDigestName();
} else {
subtree = getParent().getCombination().toString('/','/');
}
String customWorkspace = getParent().getParent().getCustomWorkspace();
if (customWorkspace != null) {
// Use custom workspace as defined in the matrix project settings.
FilePath ws = n.getRootPath().child(getEnvironment(listener).expand(customWorkspace));
// We allow custom workspaces to be used concurrently between jobs.
return Lease.createDummyLease(ws.child(subtree));
} else {
// Use default workspace as assigned by Hudson.
Node node = getBuiltOn();
FilePath ws = node.getWorkspaceFor(getParent().getParent());
// Allocate unique workspace (not to be shared between jobs and runs).
return wsl.allocate(ws.child(subtree));
}
}
}
}
......@@ -27,15 +27,20 @@ THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<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:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<p:config-disableBuild/>
<f:section title="${%Advanced Project Options}">
<f:advanced>
<p:config-quietPeriod />
<p:config-retryCount />
<p:config-blockWhenUpstreamBuilding />
<p:config-customWorkspace />
</f:advanced>
</f:section>
<p:config-scm/>
<p:config-trigger>
<p:config-upstream-pseudo-trigger />
</p:config-trigger>
......
......@@ -26,10 +26,5 @@ THE SOFTWARE.
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>
<p:config-customWorkspace />
</j:jelly>
\ No newline at end of file
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, id:cactusman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<!-- custom workspace -->
<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">
<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>
# The MIT License
#
# Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
Use\ custom\ workspace=\u30ab\u30b9\u30bf\u30e0\u30ef\u30fc\u30af\u30b9\u30da\u30fc\u30b9\u306e\u4f7f\u7528
# The MIT License
#
# Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
Use\ custom\ workspace=\u30ab\u30b9\u30bf\u30e0\u30ef\u30fc\u30af\u30b9\u30da\u30fc\u30b9\u306e\u4f7f\u7528
Directory=\u30c7\u30a3\u30ec\u30af\u30c8\u30ea
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册