Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-8848] allow custom workspaces for maven jobs
  • Loading branch information
kutzi authored and kohsuke committed Apr 19, 2011
1 parent 1f8ac36 commit e65f893
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 109 deletions.
11 changes: 0 additions & 11 deletions core/src/main/java/hudson/matrix/MatrixBuild.java
Expand Up @@ -323,17 +323,6 @@ public void post2(BuildListener listener) throws Exception {
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);
}

}

/**
Expand Down
33 changes: 0 additions & 33 deletions core/src/main/java/hudson/matrix/MatrixProject.java
Expand Up @@ -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);
}
Expand Down Expand Up @@ -229,28 +224,6 @@ public void setTouchStoneResultCondition(Result touchStoneResultCondition) {
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();
Expand Down Expand Up @@ -594,12 +567,6 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
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");
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/hudson/model/AbstractBuild.java
Expand Up @@ -394,6 +394,11 @@ protected final Node getCurrentNode() {
* 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()));
}
Expand Down
38 changes: 38 additions & 0 deletions core/src/main/java/hudson/model/AbstractProject.java
Expand Up @@ -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);

Expand Down Expand Up @@ -1629,6 +1636,12 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
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 {
Expand Down Expand Up @@ -1942,4 +1955,29 @@ public static AbstractProject resolveForCLI(
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();
}
}
11 changes: 0 additions & 11 deletions core/src/main/java/hudson/model/FreeStyleBuild.java
Expand Up @@ -45,15 +45,4 @@ public FreeStyleBuild(FreeStyleProject project, File buildDir) throws IOExceptio
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);
}
}
}
43 changes: 0 additions & 43 deletions core/src/main/java/hudson/model/FreeStyleProject.java
Expand Up @@ -39,12 +39,6 @@
* @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
Expand All @@ -62,43 +56,6 @@ protected Class<FreeStyleBuild> getBuildClass() {
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;
}
Expand Down
Expand Up @@ -92,7 +92,8 @@ THE SOFTWARE.
<f:optionalBlock name="maven.resolveDependencies" title="${%Resolve Dependencies during Pom parsing}"
checked="${it.isResolveDependencies()}" />
<f:optionalBlock name="maven.processPlugins" title="${%Process Plugins during Pom parsing}"
checked="${it.isProcessPlugins()}" />
checked="${it.isProcessPlugins()}" />
<p:config-customWorkspace />

<j:set var="mavenValidationLevels" value="${it.descriptor.mavenValidationLevels}" />
<f:entry title="${%Maven Validation Level}">
Expand All @@ -114,4 +115,4 @@ THE SOFTWARE.

<p:config-buildWrappers />
<p:config-publishers />
</j:jelly>
</j:jelly>
Expand Up @@ -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.
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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.

Expand Down
Expand Up @@ -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.
Expand Down

0 comments on commit e65f893

Please sign in to comment.