Skip to content

Commit

Permalink
[FIXED JENKINS-25346] - Addresses the workspace issue where files cop…
Browse files Browse the repository at this point in the history
…ied back to master are not in correct path.
  • Loading branch information
svvivek committed Feb 23, 2015
1 parent 8edc401 commit 6482c22
Showing 1 changed file with 14 additions and 4 deletions.
Expand Up @@ -28,6 +28,8 @@
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.FreeStyleProject;
import hudson.model.TopLevelItem;
import jenkins.model.Jenkins;
import java.io.File;
import java.io.PrintStream;
import java.util.logging.Level;
Expand All @@ -39,10 +41,10 @@
public class CopyToSlaveUtils {

public static FilePath getProjectWorkspaceOnMaster(AbstractBuild build, PrintStream logger) {
return getProjectWorkspaceOnMaster(build.getProject(), logger);
return getProjectWorkspaceOnMaster(build, build.getProject(), logger);
}

public static FilePath getProjectWorkspaceOnMaster(AbstractProject project, PrintStream logger) {
public static FilePath getProjectWorkspaceOnMaster(AbstractBuild build, AbstractProject project, PrintStream logger) {
FilePath projectWorkspaceOnMaster;

// free-style projects
Expand All @@ -54,11 +56,19 @@ public static FilePath getProjectWorkspaceOnMaster(AbstractProject project, Prin
projectWorkspaceOnMaster = new FilePath(new File(freeStyleProject.getCustomWorkspace()));
}
else {
projectWorkspaceOnMaster = new FilePath(new File(freeStyleProject.getRootDir(), "workspace"));
projectWorkspaceOnMaster = Jenkins.getInstance().getWorkspaceFor(freeStyleProject);
}
}
else {
projectWorkspaceOnMaster = new FilePath(new File(project.getRootDir(), "workspace"));
String pathOnMaster = Jenkins.getInstance().getWorkspaceFor((TopLevelItem)project.getRootProject()).getRemote();
String parts[] = build.getWorkspace().getRemote().
split("workspace" + File.separator + project.getRootProject().getName());
if (parts.length > 1) {
// This happens for the non free style projects (like multi configuration projects, etc)
// So we'll just add the extra part of the path to the workspace
pathOnMaster += parts[1];
}
projectWorkspaceOnMaster = new FilePath(new File(pathOnMaster));
}

try {
Expand Down

0 comments on commit 6482c22

Please sign in to comment.