Jenkins:从主服务器上的build文件夹复制到从服务器上的工作区

时间:2018-07-12 09:21:29

标签: jenkins build

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

3 个答案:

答案 0 :(得分:0)

如果您使用管道,则可以使用stash / ustash选项。

将junitResult.xml文件存放在主节点上,然后在另一个节点上存放到工作区。

答案 1 :(得分:0)

1)安装“复制工件插件”
2)主作业发布步骤:归档工件 junitResult.xml
3)从属作业构建步骤:复制其他项目中的工件-指定项目名称,要构建的工件和要复制的工件- junitResult.xml

答案 2 :(得分:0)

如果有人对此主题感兴趣, 我已经成功地通过使用Groovy脚本来做到了。就我而言(与Jenkins集成TestComplete插件),我将一个名为junitResult.xml的文件复制到了工作区。这是秘诀:

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 )
相关问题