Copying Artifacts Between Builds in a Jenkins Workflow

As it’s name suggests, the copyartifact-plugin provides a build step in support of copying artifacts between Jenkins builds. We recently made updates to this plugin that allow it to be used within a Jenkins Workflow (will be available in v1.34 of the plugin).

It’s currently available as a “Core Step”, which means you use it through the generic step workflow step e.g.

node {
   // setup env..
   // copy the deployment unit from another Job...
   step ([$class: 'CopyArtifact',
          projectName: 'webapp_build',
          filter: 'target/orders.war']);
   // deploy 'target/orders.war' to an app host
}

As you’d guess, the above example simply copies a Java war file artifact from another Jenkins job and deploys it “somewhere”. All other config options that the copyartifact-plugin supports are also available. The easiest way to test/browse all options is through the Workflow script “Snippet Generator” (available on the workflow configuration screen below the workflow script textarea).

The next obvious step is to provide a “native” copyartifacts workflow step.

 

Tom Fennelly
Engineer
CloudBees

 

Blog Categories: 

Comments

How do I specify which build's artifacts I want to copy? This way only the latest succesfull one can be deployed.

I was able to specify build to copy from by adding the following parameter: parameters: 'BUILD_NUMBER=123'

If you want to select a specific build from which to copy artifacts, you need to configure the "selector" attribute. For an example of how this is used in the Blue Ocean CI build, see here: https://github.com/jenkinsci/blueocean-acceptance-test/blob/master/Jenkinsfile - search for "selector" and how it's used for copy artifacts.

Add new comment