使用 Jenkins 管道在节点之间复制构建工件

Copy build artifact between nodes using Jenkins pipeline

我正在尝试将现有的 Jenkins 构建作业移动到单个 Jenkins 2 管道,并想知道是否可以在构建中将文件从一个节点复制到另一个节点。我的想法是:

Node A (Windows)
  Checkout scm
  Execute ant build
  Archive artifact (or whatever required action)
Node B (Unix)
  Checkout scm
  Copy build artifact from node A --> is this possible ?
  Execute ant build
  Then followed by tests...

我试过使用复制工件步骤,但它似乎没有正常工作,所以我想知道是否有办法在管道中间复制文件,或者我是否必须这样做保持当前的构建架构(使用 copy artifact plugin,但使用完全独立的构建作业)。

是的,这可以使用 stash/unstash 步骤。

关于这方面的教程也可以在 Jenkins Blog(专注于并行执行)中找到:

parallel (
    "stream 1" : { 
                     node { 
                           unstash "binary"                           
                           sh "sleep 20s" 
                           sh "echo hstream1"
                       } 
                   },
    "stream 2" : { 
                     node { 
                           unstash "binary"
                           sh "echo hello2"
                           sh "hashtag fail"                                                       
                       } 
                   }
          )