Jenkins:从主服务器上的build文件夹复制到从服务器上的工作区 [英] Jenkins: Copy from build folder on master to workspace on slave

查看:359
本文介绍了Jenkins:从主服务器上的build文件夹复制到从服务器上的工作区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的Jenkins实例上安装了Test Complete插件,我想将在主服务器上的build文件夹中生成的junitResult.xml复制到从服务器上的工作空间.是否可以安全地执行此操作?

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?

推荐答案

如果有人对此主题感兴趣, 我已经成功地通过使用Groovy脚本来做到了.就我而言(与Jenkins集成TestComplete插件),我将一个名为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 )

这篇关于Jenkins:从主服务器上的build文件夹复制到从服务器上的工作区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆