Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy artifact within a jenkins pipeline

I have a Jenkins pipeline job that archives an Artifact in its first phase, I then need to copy that Artifact in another stage of the pipeline build

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/'])
}

With this I get a unable to find a build for artifact copy

When the artifact is created it is saved here:

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

How do I access the created artifact from within a pipeline job?

like image 600
Richlewis Avatar asked Dec 02 '16 11:12

Richlewis


1 Answers

I needed this recently, and none of the other solutions here did exactly what I wanted, because I need to use multiple parameter filters for my selection. Here's what I did using the "Run Selector Plugin" in addition to the direct calling of the "Copy Artifact Plugin":

Step One: Select the build number you need.

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

Step Two: Copy (updated 2017-11: Native pipeline support now!).

        copyArtifacts(
          projectName: 'prereq_rpms',
          filter: '**/*.rpm',
          fingerprintArtifacts: true,
          target: 'prereq',
          flatten: true,
          selector: specific(prereq_build.getId())
        )
like image 164
Aaron D. Marasco Avatar answered Oct 03 '22 05:10

Aaron D. Marasco