简体   繁体   中英

Jenkins: Copy from build folder on master to workspace on slave

I have installed Test Complete plugin on my Jenkins instance and I would like to copy the junitResult.xml that is generated in the build folder on the master to the workspace on the slave. Is it possible to do this securly?

if you use the pipeline, then you can use stash/ustash option.

Stash the junitResult.xml file on master node, and then unstash on another node to workspace.

1) install "Copy Artifact Plugin"
2) master job post build step: archive the artifacts junitResult.xml
3) slave job build step: Copy artifacts from other projects - specify project name, which build and artifact to copy - junitResult.xml

If someone is interested by this topic, I have sucessfully done it by using a groovy script. In my case (TestComplete plugin integration with Jenkins), I copied a file named junitResult.xml to the workspace. Here is the scipt:

import hudson.FilePath;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;

FilePath getMasterLogDirectory(AbstractBuild build) throws IOException, InterruptedException {
  String buildDir = build.getRootDir().getAbsolutePath();
  FilePath masterLogDirectory = new FilePath(new File(buildDir + File.separator + "junitResult.xml"));
  return masterLogDirectory;
}

FilePath getSlaveWorkspace(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
  String workspacePath = build.getEnvironment(listener).get("WORKSPACE");
    if (workspacePath == null) {
      throw new IOException(Messages.TcTestBuilder_InternalError());
    }

  FilePath projectWorkspaceOnSlave = new FilePath(launcher.getChannel(), workspacePath);
  projectWorkspaceOnSlave.mkdirs();
  return projectWorkspaceOnSlave.absolutize();
}

def junitName = "junitResult.xml"

FilePath slaveWorkspacePath = getSlaveWorkspace(build, launcher, listener)

FilePath  slaveJunitFilePath = new FilePath(slaveWorkspacePath, junitName);

getMasterLogDirectory(build).copyTo(slaveJunitFilePath )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM