Copy artifact within a jenkins pipeline

£可爱£侵袭症+ 提交于 2019-12-03 14:10:57

问题


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?


回答1:


Figured this one out, so using the var ${BUILD_NUMBER} you can access artifacts un the current pipeline

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



回答2:


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())
        )



回答3:


In pipeline plugin, there is a new feature called 'stash', 'unstash' instead of artifacts.

Artifact: Archives are designed for longer term file storage (e.g., intermediate binaries from your builds). Artifact requires more storage space and resource management.

Stash: Saves a set of files and use later in the same build, generally on another node/workspace. stash and unstash steps are designed for use with small files. Stash/unstash can be used inside a pipeline with just assigning a name to the stash & works only locally.

Here is a good example for stash/unstash: Tutorial



来源:https://stackoverflow.com/questions/40930718/copy-artifact-within-a-jenkins-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!