在jenkins管道中复制工件

Ric*_*wis 7 groovy jenkins jenkins-pipeline

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

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/'])
}
Run Code Online (Sandbox Code Playgroud)

有了这个,我得到了一个 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
Run Code Online (Sandbox Code Playgroud)

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

Ric*_*wis 7

想出这个,所以使用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/'])
Run Code Online (Sandbox Code Playgroud)


Aar*_*sco 6

我最近需要这个,这里没有其他解决方案完全符合我的要求,因为我需要使用多个参数过滤器来进行选择.除了直接调用" 复制工件插件 " 之外,这是我使用" 运行选择器插件 " 所做的事情:

第一步:选择您需要的内部版本号.

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

第二步:复制(更新2017-11:现在的本地管道支持!).

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