Skip to content
Permalink
Browse files
[FIXED JENKINS-12281] It is now possible to remove {{HUDSON_HOME}} fr…
…om the list of base locations for copy to slave operations
  • Loading branch information
rseguy committed Jan 13, 2012
1 parent 0b312a1 commit 74f4fc505ba0007e2690a3ebec14c9c288eae865
@@ -1,7 +1,7 @@
/*
* The MIT License
*
* Copyright (c) 2009-2011, Manufacture Française des Pneumatiques Michelin, Romain Seguy
* Copyright (c) 2009-2012, Manufacture Française des Pneumatiques Michelin, Romain Seguy
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -37,17 +37,21 @@
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrapperDescriptor;
import java.io.IOException;
import javax.servlet.ServletException;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.jvnet.localizer.Localizable;
import org.jvnet.localizer.ResourceBundleHolder;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

/**
* @author Romain Seguy (http://openromain.blogspot.com)
*/
public class CopyToSlaveBuildWrapper extends BuildWrapper {

public final static String RELATIVE_TO_HOME = "home";
public final static String RELATIVE_TO_SOMEWHERE_ELSE = "somewhereElse";
public final static String RELATIVE_TO_USERCONTENT = "userContent";
public final static String RELATIVE_TO_WORKSPACE = "workspace";

@@ -78,6 +82,11 @@ else if(StringUtils.isBlank(relativeTo)) {
this.hudsonHomeRelative = false; // force hudsonHomeRelative to false to not use it anymore
}

@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
}

@Override
public Environment setUp(AbstractBuild build, final Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
EnvVars env = build.getEnvironment(listener);
@@ -95,17 +104,23 @@ public Environment setUp(AbstractBuild build, final Launcher launcher, BuildList
}
else {
FilePath rootFilePathOnMaster;

if(RELATIVE_TO_WORKSPACE.equals(relativeTo)) {
rootFilePathOnMaster = CopyToSlaveUtils.getProjectWorkspaceOnMaster(build, listener.getLogger());
}
else if(RELATIVE_TO_HOME.equals(relativeTo)) {
else if(getDescriptor().isSomewhereElseEnabled() && RELATIVE_TO_SOMEWHERE_ELSE.equals(relativeTo)) {
rootFilePathOnMaster = new FilePath(
Hudson.getInstance().getChannel(),
env.expand(getDescriptor().getSomewhereElsePath()));
}
else if(getDescriptor().isRelativeToHomeEnabled() && RELATIVE_TO_HOME.equals(relativeTo)) { // JENKINS-12281
rootFilePathOnMaster = Hudson.getInstance().getRootPath();
}
else {
rootFilePathOnMaster = Hudson.getInstance().getRootPath().child("userContent");
}

FilePath projectWorkspaceOnSlave = build.getProject().getWorkspace();
FilePath projectWorkspaceOnSlave = build.getWorkspace();

String includes = env.expand(getIncludes());
String excludes = env.expand(getExcludes());
@@ -165,8 +180,35 @@ public boolean isFlatten() {
@Extension
public static class DescriptorImpl extends BuildWrapperDescriptor {

private boolean relativeToHomeEnabled; // JENKINS-12281
private boolean somewhereElseEnabled;
private String somewhereElsePath;

public DescriptorImpl() {
super(CopyToSlaveBuildWrapper.class);
load();
}

@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
try {
relativeToHomeEnabled = req.getSubmittedForm().getBoolean("relativeToHomeEnabled");

somewhereElseEnabled = req.getSubmittedForm().getBoolean("somewhereElseEnabled");

somewhereElsePath = req.getSubmittedForm().getString("somewhereElsePath");
if(StringUtils.isBlank(somewhereElsePath)) {
somewhereElsePath = null;
somewhereElseEnabled = false;
}

save();

return true;
}
catch (ServletException e) {
return false;
}
}

@Override
@@ -179,6 +221,18 @@ public boolean isApplicable(AbstractProject<?, ?> item) {
return true;
}

public String getSomewhereElsePath() {
return somewhereElsePath;
}

public boolean isRelativeToHomeEnabled() {
return relativeToHomeEnabled;
}

public boolean isSomewhereElseEnabled() {
return somewhereElseEnabled;
}

}

}
@@ -1,7 +1,7 @@
<!--
- The MIT License
-
- Copyright (c) 2009-2011, Manufacture Française des Pneumatiques Michelin, Romain Seguy
- Copyright (c) 2009-2012, Manufacture Française des Pneumatiques Michelin, Romain Seguy
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
@@ -27,10 +27,22 @@
<f:textbox/>
</f:entry>
<f:entry title="${%RelativeTo}" field="relativeTo">
<f:radio name="copytoslave.relativeTo" value="userContent" checked="${instance.relativeTo == 'userContent' or instance.relativeTo == null}" id="relativeTo.userContent"/>
<f:radio name="copytoslave.relativeTo"
value="userContent"
checked="${instance.relativeTo == 'userContent' or instance.relativeTo == null}"
id="relativeTo.userContent"/>
<label class="attach-previous">${%UserContentRelative}</label><br/>
<f:radio name="copytoslave.relativeTo" value="home" checked="${instance.relativeTo == 'home'}" id="relativeTo.home"/>
<label class="attach-previous">${%HomeRelative}</label><br/>
<j:if test="${descriptor.somewhereElseEnabled}">
<f:radio name="copytoslave.relativeTo"
value="somewhereElse"
checked="${instance.relativeTo == 'somewhereElse'}"
id="relativeTo.somewhereElse"/>
<label class="attach-previous"><code>${descriptor.somewhereElsePath}</code></label><br/>
</j:if>
<j:if test="${descriptor.relativeToHomeEnabled}">
<f:radio name="copytoslave.relativeTo" value="home" checked="${instance.relativeTo == 'home'}" id="relativeTo.home"/>
<label class="attach-previous">${%HomeRelative}</label><br/>
</j:if>
<f:radio name="copytoslave.relativeTo" value="workspace" checked="${instance.relativeTo == 'workspace'}" id="relativeTo.workspace"/>
<label class="attach-previous">${%WorkspaceRelative}</label>
</f:entry>
@@ -1,6 +1,6 @@
# The MIT License
#
# Copyright (c) 2009-2011, Manufacture Fran\u00e7aise des Pneumatiques Michelin, Romain Seguy
# Copyright (c) 2009-2012, Manufacture Fran\u00e7aise des Pneumatiques Michelin, Romain Seguy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -22,9 +22,11 @@

Excludes=Files to exclude from the copy
Flatten=Flatten directories
HomeRelative=<code>HUDSON_HOME</code> (not advised)
HomeRelative=<code>$JENKINS_HOME</code> (not advised)
Includes=Files to copy
IncludeAntExcludes=Include Ant''s default excludes
RelativeTo=Paths are relative to
UserContentRelative=<code>HUDSON_HOME/userContent</code> (preferred)
SomewhereElseBeginning=<code>
SomewhereElseEnd=</code>
UserContentRelative=<code>$JENKINS_HOME/userContent</code>
WorkspaceRelative=This job''s workspace on the master (not advised)
@@ -1,6 +1,6 @@
# The MIT License
#
# Copyright (c) 2009-2011, Manufacture Fran\u00e7aise des Pneumatiques Michelin, Romain Seguy
# Copyright (c) 2009-2012, Manufacture Fran\u00e7aise des Pneumatiques Michelin, Romain Seguy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -22,9 +22,9 @@

Excludes=Fichiers &agrave; exclure de la copie
Flatten=Applatir les r&eacute;pertoires
HomeRelative=<code>HUDSON_HOME</code> (&agrave; &eacute;viter)
HomeRelative=<code>$JENKINS_HOME</code> (&agrave; &eacute;viter)
Includes=Fichiers &agrave; copier
IncludeAntExcludes=Inclure les exclusions par d&eacute;faut de Ant
RelativeTo=Les chemins sp&eacute;cifi&eacute;es sont relatifs &agrave;
UserContentRelative=<code>HUDSON_HOME/userContent</code> (&agrave; privil&eacute;gier)
UserContentRelative=<code>$JENKINS_HOME/userContent</code>
WorkspaceRelative=Le workspace de ce job sur le noeud ma&icirc;tre (&agrave; &eacute;viter)
@@ -0,0 +1,42 @@
<!--
- The MIT License
-
- Copyright (c) 2012, Manufacture Française des Pneumatiques Michelin, Romain Seguy
-
- 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.
-->

<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:section title="${%CopyToSlaveConfiguration}">
<f:optionalBlock title="${%EnableSomewhereElse}"
name="somewhereElseEnabled"
field="somewhereElseEnabled"
checked="${it.somewhereElseEnabled}"
inline="true">
<f:entry title="${%SomewhereElsePath}" field="somewhereElsePath">
<f:textbox/>
</f:entry>
</f:optionalBlock>
<f:optionalBlock title="${%EnableHomeRelative}"
name="relativeToHomeEnabled"
field="relativeToHomeEnabled"
checked="${it.relativeToHomeEnabled}"
inline="true"/>
</f:section>
</j:jelly>
@@ -0,0 +1,26 @@
# The MIT License
#
# Copyright (c) 2012, Manufacture Fran\u00e7aise des Pneumatiques Michelin, Romain Seguy
#
# 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.

CopyToSlaveConfiguration=Copy To Slave Options
EnableHomeRelative=Enable the "Paths are relative to $JENKINS_HOME" option
EnableSomewhereElse=Define an additional "Paths are relative to" option
SomewhereElsePath=Path
@@ -1,7 +1,7 @@
<!--
- The MIT License
-
- Copyright (c) 2010-2011, Manufacture Française des Pneumatiques Michelin, Romain Seguy
- Copyright (c) 2010-2012, Manufacture Française des Pneumatiques Michelin, Romain Seguy
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
@@ -24,14 +24,5 @@

<div>
Specify the base location for the paths that are specified in the <strong>
Includes</strong> and <strong>Excludes</strong> fields:
<ul>
<li>The <code>HUDSON_HOME/userContent</code> option should be preferred
since it is the standard folder used by Hudson/Jenkins to expose files to
users.</li>
<li>Using <code>HUDSON_HOME</code> is not advised since it exposes the
whole Hudson/Jenkins folder.</li>
<li>Using the job's <a href="ws/">workspace</a> is not advised since it
requires manually creating it before running a first build.</li>
</ul>
Includes</strong> and <strong>Excludes</strong> fields.
</div>
@@ -0,0 +1,30 @@
<!--
- The MIT License
-
- Copyright (c) 2012, Manufacture Française des Pneumatiques Michelin, Romain Seguy
-
- 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.
-->

<div>
If this option is enabled, then users will be able to select
<code>$JENKINS_HOME</code> as a possible base location for copy to slave
operations, thus exposing the whole Hudson/Jenkins folder. <strong>As such,
enabling this option is highly discouraged.</strong>
</div>
@@ -0,0 +1,30 @@
<!--
- The MIT License
-
- Copyright (c) 2012, Manufacture Française des Pneumatiques Michelin, Romain Seguy
-
- 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.
-->

<div>
Optionally specify an additional entry which will be choosable as the base
location for copy to slave operations (in addition to
<code>$JENKINS_HOME/userContent</code>, the job workspace and, if enabled,
<code>$JENKINS_HOME</code>).
</div>
@@ -1,7 +1,7 @@
<!--
- The MIT License
-
- Copyright (c) 2009-2011, Manufacture Française des Pneumatiques Michelin, Romain Seguy
- Copyright (c) 2009-2012, Manufacture Française des Pneumatiques Michelin, Romain Seguy
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
@@ -29,7 +29,7 @@
node itself).<br/>
This is useful, for example, when some files required for the build to take
place are not present in the SCM, but are located in one of the three
following locations: <code>HUDSON_HOME/userContent</code>, <code>HUDSON_HOME</code>,
or directly in the project's <a href='ws/'>workspace</a> (on the
master node).
following locations: <code>$JENKINS_HOME/userContent</code>,
<code>$JENKINS_HOME</code>, or directly in the project's
<a href='ws/'>workspace</a> (on the master node).
</div>

0 comments on commit 74f4fc5

Please sign in to comment.