Permalink
Browse files

[JENKINS-17730] Support for Custom Workspace

  • Loading branch information...
syl20bnr committed May 25, 2013
1 parent dce79a6 commit f6c80c0d541233414830d9c72236eedbe2ac2dc0
@@ -26,31 +26,25 @@ of this software and associated documentation files (the "Software"), to deal

import hudson.Extension;
import hudson.Launcher;
import hudson.Util;
import hudson.model.*;
import hudson.model.Descriptor.FormException;
import hudson.model.ParameterDefinition;
import hudson.model.ParameterDefinition.ParameterDescriptor;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Queue.FlyweightTask;
import hudson.model.labels.LabelAtom;
import hudson.scm.PollingResult;
import hudson.scm.NullSCM;
import hudson.scm.SCM;
import hudson.triggers.SCMTrigger.SCMTriggerCause;
import hudson.triggers.TimerTrigger.TimerTriggerCause;
import hudson.util.AlternativeUiTextProvider;
import hudson.util.FormValidation;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.ServletException;

import jenkins.model.Jenkins;
import jenkins.util.TimeDuration;

import net.sf.json.JSONObject;
@@ -75,6 +69,7 @@ of this software and associated documentation files (the "Software"), to deal
private transient boolean delete = false;
private transient boolean processThisJobOnly = false;
private transient boolean initiator = false;
private transient String customWorkspace = null;
private String generatedJobName = "";
private String generatedDisplayJobName = "";

@@ -83,6 +78,7 @@ public JobGenerator(ItemGroup parent, String name) {
super(parent, name);
}

@Override
public void doBuild(StaplerRequest req,
StaplerResponse rsp,
TimeDuration delay) throws IOException ,
@@ -184,13 +180,25 @@ protected void submit(StaplerRequest req, StaplerResponse rsp)
throws IOException, ServletException, FormException {
super.submit(req, rsp);
JSONObject json = req.getSubmittedForm();
JSONObject o = json.getJSONObject(
"plugin-jobgenerator-GeneratedJobConfig");
if(o != null) {
String k = "generatedJobName";
if(o.has(k)){ this.generatedJobName = o.getString(k); }
k = "generatedDisplayJobName";
if(o.has(k)){ this.generatedDisplayJobName = o.getString(k); }

String k = "plugin-jobgenerator-GeneratedJobConfig";
JSONObject o;

if(json.has(k)){
o = json.getJSONObject(k);
if(o != null) {
k = "generatedJobName";
if(o.has(k)){ this.generatedJobName = o.getString(k); }
k = "generatedDisplayJobName";
if(o.has(k)){ this.generatedDisplayJobName = o.getString(k); }
}
}

if(req.hasParameter("customWorkspace")) {
customWorkspace = Util.fixEmptyAndTrim(req.getParameter(
"customWorkspace.directory"));
} else {
customWorkspace = null;
}
}

@@ -248,6 +256,14 @@ public void setGeneratedDisplayJobName(String name){
this.generatedDisplayJobName = name;
}

public String getCustomWorkspace() {
return this.customWorkspace;
}

public void setCustomWorkspace(String customWorkspace) {
this.customWorkspace= Util.fixEmptyAndTrim(customWorkspace);
}

public boolean getProcessThisJobOnly(){
return this.processThisJobOnly;
}
@@ -288,6 +304,15 @@ public FormValidation doCheckGeneratedJobName(
}
return FormValidation.validateRequired(value);
}

public FormValidation doCheckCustomWorkspace(
@QueryParameter(value="customWorkspace.directory") String customWorkspace){
if(Util.fixEmptyAndTrim(customWorkspace)==null)
return FormValidation.error(
Messages.JobGenerator_CustomWorkspaceEmpty());
else
return FormValidation.ok();
}

public String getDefaultEntriesPage(){
return getViewPage(FreeStyleProject.class,
@@ -0,0 +1,31 @@
<!--
The MIT License
Copyright (c) 2013, Sylvain Benner.
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.
-->

<!--
Additional entries in the advanced section.
-->
<?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:p="/lib/hudson/project">
<p:config-customWorkspace />
</j:jelly>
@@ -23,3 +23,4 @@
#

JobGenerator.Messages=Job Generator
JobGenerator.CustomWorkspaceEmpty=Custom workspace is empty.

0 comments on commit f6c80c0

Please sign in to comment.