【问题标题】:Copy artifact within a jenkins pipeline在詹金斯管道中复制工件
【发布时间】:2017-04-17 06:37:50
【问题描述】:

我有一个 Jenkins 管道作业,它在第一阶段存档一个工件,然后我需要在管道构建的另一个阶段复制该工件

node {
  stage 'Stage 1 of build'
  // Run tests, if successful archive the artifact
  archiveArtifacts artifacts: 'build/test.js', excludes: null
 stage 'Stage 2 of build'
 // want to copy artifact from stage 1 of the build
 step([$class: 'CopyArtifact', filter: 'build/test.js', fingerprintArtifacts: true, flatten: true, projectName: 'echo-develop-js-pipeline', selector: [$class: 'WorkspaceSelector'], target: './client/public/vendor/echo/'])
}

有了这个我得到一个unable to find a build for artifact copy

创建工件时,它会保存在这里:

http://localhost:8181/view/Echo JS Develop/job/echo-develop-js-pipeline/233/artifact/build/test.js

如何从管道作业中访问创建的工件?

【问题讨论】:

    标签: jenkins groovy jenkins-pipeline


    【解决方案1】:

    我最近需要这个,这里没有其他解决方案完全符合我的要求,因为我需要使用多个参数过滤器进行选择。除了直接调用“Copy Artifact Plugin”之外,这是我使用“Run Selector Plugin”所做的:

    第一步:选择你需要的版本号。

    prereq_build = selectRun filter: parameters("TARGET_OS=${TARGET_OS},GIT_BRANCH_NAME=${GIT_BRANCH_NAME}"), job: 'prereq_rpms', selector: status('STABLE'), verbose: true
    

    第二步:复制(2017-11 更新:现在支持原生管道!)。

            copyArtifacts(
              projectName: 'prereq_rpms',
              filter: '**/*.rpm',
              fingerprintArtifacts: true,
              target: 'prereq',
              flatten: true,
              selector: specific(prereq_build.getId())
            )
    

    【讨论】:

    • Step Two: Copy (updated 2017-11: Native pipeline support now!)....终于,他们有了对这个核心功能的原生支持!
    • 是的,恕我直言,这属于“应该是核心功能”bin,而不是插件。
    【解决方案2】:

    想通了这一点,因此使用 var ${BUILD_NUMBER} 您可以访问当前管道中的工件

    step([$class: 'CopyArtifact', filter: 'build/test.js', fingerprintArtifacts: true, flatten: true, projectName: 'echo-develop-js-pipeline', selector: [$class: 'SpecificBuildSelector', buildNumber: '${BUILD_NUMBER}'], target: './client/public/vendor/echo/'])
    

    【讨论】:

    • 有(终于)原生管道支持,它几乎是一个直接的替代品,但具有更清晰的选择界面。我也更新了我的答案以显示它。
    • 如何计算触发的内部版本号?由于当前作业的多个实例触发了不同的下游作业(例如使用不同的参数),我不能采取最后一个(成功或最后一个工件)。
    【解决方案3】:

    在管道插件中,有一个名为“stash”、“unstash”的新功能,而不是工件。

    工件:存档专为长期文件存储而设计(例如,来自您的构建的中间二进制文件)。 Artifact 需要更多的存储空间和资源管理。

    Stash:保存一组文件并稍后在同一构建中使用,通常在另一个节点/工作区上。 stash 和 unstash 步骤设计用于小文件。 Stash/unstash 可以在管道内使用,只需为存储分配一个名称,并且只能在本地工作。

    这里是 stash/unstash 的一个很好的例子:Tutorial

    【讨论】:

    • stash 还说要限制尺寸,并不是一刀切。在单个工作中,archive/unarchive 更好。
    猜你喜欢
    • 2019-02-27
    • 1970-01-01
    • 1970-01-01
    • 2019-01-09
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多