Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-10691] Added an option to override destination folder …
…on master node
  • Loading branch information
rseguy committed Oct 3, 2011
1 parent 7116f4d commit 62d8cfd
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 41 deletions.
5 changes: 2 additions & 3 deletions README.md
Expand Up @@ -4,17 +4,16 @@ Copyright © 2009-2011, Manufacture Française des Pneumatiques Michelin, Ro

About this plugin
-----------------
The Copy To Slave plugin is meant to be used from [Hudson][1] or [Jenkins][2] to provide a way to copy files located somewhere on Hudson's/Jenkins' master node to the jobs' workspaces. Please take a look at [Jenkins' wiki][3] to get detailed information.
The Copy To Slave plugin is meant to be used from or [Jenkins][2] to provide a way to copy files located somewhere on Jenkins' master node to the jobs' workspaces. Please take a look at [Jenkins' wiki][3] to get detailed information.

Installation
------------
The Copy To Slave plugin can be installed from any Hudson or Jenkins installation connected to the Internet using the **Plugin Manager** screen.
The Copy To Slave plugin can be installed from any Jenkins installation connected to the Internet using the **Plugin Manager** screen.

Source code
-----------
The primary location for the source code of this plugin is on [Jenkins' SVN repository][4]. It is also mirrored on [GitHub][5] for conveniency.

[1]: http://hudson-ci.org/
[2]: http://jenkins-ci.org/
[3]: http://wiki.jenkins-ci.org/display/JENKINS/Copy+To+Slave+Plugin
[4]: https://svn.jenkins-ci.org/trunk/hudson/plugins/copy-to-slave/
Expand Down
34 changes: 3 additions & 31 deletions pom.xml
Expand Up @@ -2,18 +2,17 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jvnet.hudson.plugins</groupId>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.375</version>
<version>1.409</version>
<relativePath>../pom.xml</relativePath>
</parent>

<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>copy-to-slave</artifactId>
<packaging>hpi</packaging>
<name>Copy To Slave Plugin</name>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Copy+To+Slave+Plugin</url>
<version>1.3.1-SNAPSHOT</version>
<version>1.4-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -28,31 +27,4 @@
</developer>
</developers>


<!-- see http://groups.google.com/group/hudson-dev/browse_thread/thread/83e34c639eec470a for the rationale behind this -->
<build>
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<goals>deploy</goals>
</configuration>
</plugin>
</plugins>
</build>

<!-- see http://groups.google.com/group/hudson-dev/browse_thread/thread/83e34c639eec470a for the rationale behind this -->
<scm>
<connection>scm:svn:https://guest@svn.jenkins-ci.org/trunk/hudson/plugins/copy-to-slave/</connection>
<developerConnection>scm:svn:https://svn.jenkins-ci.org/trunk/hudson/plugins/copy-to-slave/</developerConnection>
<url>https://hudson.dev.java.net/source/browse/hudson/trunk/hudson/plugins/copy-to-slave</url>
</scm>

<!-- see http://groups.google.com/group/hudson-dev/browse_thread/thread/6ea03cf2b527376c for the rationale behind this -->
<distributionManagement>
<repository>
<id>java.net-m2-repository</id>
<url>http://maven.jenkins-ci.org/content/repositories/releases/</url>
</repository>
</distributionManagement>
</project>
Expand Up @@ -37,6 +37,7 @@
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Notifier;
import hudson.tasks.Publisher;
import java.io.File;
import java.io.IOException;
import org.apache.commons.lang.StringUtils;
import org.jvnet.localizer.Localizable;
Expand All @@ -50,11 +51,15 @@ public class CopyToMasterNotifier extends Notifier {

private final String includes;
private final String excludes;
private final boolean overrideDestinationFolder;
private final String destinationFolder;

@DataBoundConstructor
public CopyToMasterNotifier(String includes, String excludes) {
public CopyToMasterNotifier(String includes, String excludes, boolean overrideDestinationFolder, String destinationFolder) {
this.includes = includes;
this.excludes = excludes;
this.overrideDestinationFolder = overrideDestinationFolder;
this.destinationFolder = destinationFolder;
}

@Override
Expand All @@ -68,18 +73,25 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
env.overrideAll(build.getBuildVariables());

if(Computer.currentComputer() instanceof SlaveComputer) {
FilePath projectWorkspaceOnMaster = CopyToSlaveUtils.getProjectWorkspaceOnMaster(build, listener.getLogger());
FilePath destinationFilePath;
if(isOverrideDestinationFolder() && StringUtils.isNotBlank(getDestinationFolder())) {
destinationFilePath = new FilePath(new File(env.expand(getDestinationFolder())));
}
else {
destinationFilePath = CopyToSlaveUtils.getProjectWorkspaceOnMaster(build, listener.getLogger());
}

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

String includes = env.expand(getIncludes());
String excludes = env.expand(getExcludes());

listener.getLogger().printf("[copy-to-slave] Copying '%s', excluding %s, from '%s' on '%s' to '%s' on the master.\n",
includes, StringUtils.isBlank(excludes) ? "nothing" : '\'' + excludes + '\'', projectWorkspaceOnSlave.toURI(),
Computer.currentComputer().getNode(), projectWorkspaceOnMaster.toURI());
Computer.currentComputer().getNode(), destinationFilePath.toURI());

CopyToSlaveUtils.hudson5977(projectWorkspaceOnSlave); // HUDSON-6045
projectWorkspaceOnSlave.copyRecursiveTo(includes, excludes, projectWorkspaceOnMaster);
projectWorkspaceOnSlave.copyRecursiveTo(includes, excludes, destinationFilePath);
}
else if(Computer.currentComputer() instanceof MasterComputer) {
listener.getLogger().println(
Expand All @@ -97,6 +109,14 @@ public String getExcludes() {
return excludes;
}

public String getDestinationFolder() {
return destinationFolder;
}

public boolean isOverrideDestinationFolder() {
return overrideDestinationFolder;
}

public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.BUILD;
}
Expand Down
@@ -1,7 +1,7 @@
<!--
- The MIT License
-
- Copyright (c) 2009-2010, Manufacture Française des Pneumatiques Michelin, Romain Seguy
- Copyright (c) 2009-2011, 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
Expand Down Expand Up @@ -30,5 +30,13 @@
<f:entry title="${%Excludes}" field="excludes">
<f:textbox/>
</f:entry>
<f:optionalBlock
title="${%OverrideDestinationFolder}"
field="overrideDestinationFolder"
inline="true">
<f:entry title="${%DestinationFolder}" field="destinationFolder">
<f:textbox/>
</f:entry>
</f:optionalBlock>
</f:advanced>
</j:jelly>
@@ -1,6 +1,6 @@
# The MIT License
#
# Copyright (c) 2009-2010, Manufacture Fran\u00E7aise des Pneumatiques Michelin, Romain Seguy
# Copyright (c) 2009-2011, 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
Expand All @@ -20,5 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

DestinationFolder=Destination folder
Includes=Files to copy
Excludes=Files to exclude from the copy
OverrideDestinationFolder=Override destination folder
@@ -1,6 +1,6 @@
# The MIT License
#
# Copyright (c) 2009-2010, Manufacture Fran\u00E7aise des Pneumatiques Michelin, Romain Seguy
# Copyright (c) 2009-2011, 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
Expand All @@ -20,5 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

DestinationFolder=R&eacute;pertoire de destination
Includes=Fichiers &agrave; copier
Excludes=Fichiers &agrave; exclure de la copie
OverrideDestinationFolder=Red&eacute;finir le r&eacute;pertoire de destination
@@ -0,0 +1,30 @@
<!--
- The MIT License
-
- Copyright (c) 2011, 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>
Specify an absolute path into which the files have to be copied. If left
blank (or if <strong>Override destination folder</strong> is not checked,
files will be copied into the workspace of the current job (on the master
node).
</div>

0 comments on commit 62d8cfd

Please sign in to comment.