简体   繁体   English

在 Pipeline 中将文件从 Jenkins master 复制到 slave

[英]Copy file from Jenkins master to slave in Pipeline

I have some windows slave at my Jenkins so I need to copy file to them in pipeline.我的 Jenkins 有一些 windows 奴隶,所以我需要在管道中将文件复制到他们。 I heard about Copy To Slave and Copy Artifact plugins, but they doesn't have pipeline syntax manual.我听说过 Copy To Slave 和 Copy Artifact 插件,但它们没有管道语法手册。 So I don't know how to use them in pipeline.所以我不知道如何在管道中使用它们。

Direct copy doesn't work.直接复制不行。

def inputFile = input message: 'Upload file', parameters: [file(name: 'parameters.xml')]
new hudson.FilePath(new File("${ENV:WORKSPACE}\\parameters.xml")).copyFrom(inputFile)

This code returns and error:此代码返回错误:

Caused: java.io.IOException: Failed to copy /var/lib/jenkins/jobs/_dev/jobs/(TEST)job/builds/107/parameters.xml to d:\Jenkins\workspace\_dev\(TEST)job\parameters.xml

Is there any way to copy file from master to slave in Jenkins Pipeline?有没有办法在 Jenkins 管道中将文件从主机复制到从机?

As I understand copyFrom is executed on your Windows node, therefore the source path is not accessible. 据我了解, copyFrom是在Windows节点上执行的,因此无法访问源路径。

I think you want to look into the stash / unstash steps ( Jenkins Pipeline: Basic Steps ), which work across different nodes. 我认为您想研究stash / unstash stash步骤( Jenkins Pipeline:基本步骤 ),该步骤可在不同节点上工作。 Also this example might be helpful. 同样,此示例可能会有所帮助。

Pipeline DSL context runs on master node even that your write node('someAgentName') in your pipeline. 管道DSL上下文在master节点上运行,即使您在管道中的写入node('someAgentName')也是如此。

  • Try to use stash/unstash , but it is bad for large files. 尝试使用stash / unstash ,但这对大文件不利。
  • Try External Workspace Manager Plugin . 尝试使用外部Workspace Manager插件 It has pipelines steps and good for large files. 它具有管道步骤,适合大型文件。
  • Try to use an intermediate storage. 尝试使用中间存储。 archive() and sh("wget $url") will be helpful. archive()sh("wget $url")会有所帮助。

If the requirement is to copy an executable to the test slave and to publish the test results, this is easy to do without the Copy to Slave plugin.如果需要将可执行文件复制到测试从站并发布测试结果,则无需复制到从站插件即可轻松完成。

A shared folder should be created on each test slave (normal Windows shared folder).应该在每个测试从站上创建一个共享文件夹(普通的 Windows 共享文件夹)。

After build: Build script copies the executable to the shared directory on each slave.构建后:构建脚本将可执行文件复制到每个从站上的共享目录。 A simple batch script using copy command is sufficient for this.使用copy命令的简单批处理脚本就足够了。

stage ('Copy to slaves') {
    steps {
        bat 'call "copy-to-slave.bat"'
    }
}

During test: The test script copies the executable to another directory and runs it.在测试期间:测试脚本将可执行文件复制到另一个目录并运行它。

After test: Post-build action "Publish Robot Framework test results" can be used to report the test results.测试后:构建后动作“发布机器人框架测试结果”可用于报告测试结果。 It is not necessary to copy the test result files back to the master first.无需先将测试结果文件复制回主站。

I recommend on Pipeline: Phoenix AutoTest plugin我在Pipeline: Phoenix AutoTest插件

Jenkins plugin website: https://plugins.jenkins.io/phoenix-autotest/#documentation Jenkins插件网址: https://plugins.jenkins.io/phoenix-autotest/#documentation

GitHub repository of plugin: https://github.com/jenkinsci/phoenix-autotest-plugin GitHub 插件仓库: https://github.com/jenkinsci/phoenix-autotest-plugin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当 jenkins 作业在从机上运行时,如何使用 Jenkinsfile 管道脚本从主机读取 yaml 文件? - How to read yaml file from master using Jenkinsfile pipeline script when jenkins job is running on slave machine? 如何将作业的工作区从 jenkins 主容器复制到从容器并从从容器复制回主容器? - How to copy a workspace of a job from jenkins master to slave container and copy back from slave to master? Jenkins:从主服务器上的build文件夹复制到从服务器上的工作区 - Jenkins: Copy from build folder on master to workspace on slave 如何在Jenkins中将数据从Master复制到多个Slave - How to copy data from Master to multiple Slave in Jenkins 将文件从主PC上安装的驱动器复制到Jenkins从机 - Copy files from drive mounted on master PC to Jenkins slave machine 如何将构建XML从Master复制到Jenkins中的Slave节点? - How to copy build XMLs from Master to the Slave node in Jenkins? Jenkins主站和从站安装在CI / CD管道上 - Jenkins master and Slave installation on CI/CD pipeline 当从属设备重新启动时,主设备上的 Jenkins 管道卡住 - Jenkins pipeline on master stuck when slave reboots Jenkins 管道步骤发生在主机而不是从机上 - Jenkins pipeline step happens on master instead of slave 如何在jenkins管道脚本中从jenkins master指定jenkins slave git地址 - how to specify jenkins slave git address from jenkins master in jenkins pipeline script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM