Jenkins : Copy Artifact Plugin

Plugin Information

View Copy Artifact on the plugin site for more information.

Older versions of this plugin may not be safe to use. Please review the following warnings before using an older version:

Adds a build step to copy artifacts from another project.

The plugin lets you specify which build to copy artifacts from (e.g. the last successful/stable build, by build number, or by a build parameter). You can also control the copying process by filtering the files being copied, specifying a destination directory within the target project, etc. Click the help icon on each field to learn the details, such as selecting Maven or multiconfiguration projects or using build parameters. You can also copy from the workspace of the latest completed build of the source project, instead of its artifacts. All artifacts copied are automatically fingerprinted for you.

Pipeline syntax

Available since copyartifact-1.39

  • To copy artifacts from the latest stable build of "sourceproject"

    copyArtifacts(projectName: 'sourceproject');
  • To copy artifacts from the specific build of "downstream"

    def built = build('downstream');  // https://plugins.jenkins.io/pipeline-build-step
    copyArtifacts(projectName: 'downstream', selector: specific("${built.number}"));
  • Parameters of copyArtifacts

    parametertypedescription
    projectNamestringthe name of project (required)
    selectorBuildSelectorthe selector to select the build to copy from. If not specified, latest stable build is used.
    parametersstringcomma-separated name and value pairs (name1=value1,name2=value2) to filter the build to copy from.
    filterstringant-expression to filter artifacts to copy
    excludesstringant-expression to exclude artifacts to copy
    targetstringtarget directory to copy to
    flattenbooleanignore directory structures of artifacts
    optionalbooleando not fail the step even if no appropriate build is found.
    fingerprintArtifactsbooleanfingerprint artifacts to track builds using those artifacts. true for default
    resultVariableSuffixbooleanuseless for pipelines
  • selectors

    namefeature
    lastSuccessfulLatest successful build
    specificSpecific build
    permalinkSpecified by permalink
    lastCompletedcompleted build (ignoring build status)
    latestSavedBuildLatest saved build (marked "keep forever")
    buildParameterSpecified by a build parameter
    upstreamUpstream build that triggered this job

Configuration Notes

  • When using this plugin with a Windows slave node that is configured as a Windows service, the service should have permission to interact with desktop (select "Allow service to interact with desktop" from Jenkins Slave service properties). Otherwise you may see errors similar to this:

    ERROR: Failed to copy artifacts from ...
    hudson.util.IOException2: java.lang.IllegalAccessError: class hudson.remoting.Pipe$ConnectCommand cannot
      access its superclass hudson.remoting.Command
    at hudson.FilePath.copyRecursiveTo(FilePath.java:1526)
    at hudson.FilePath.copyRecursiveTo(FilePath.java:1451)
    at hudson.plugins.copyartifact.FilePathCopyMethod.copyAll(FilePathCopyMethod.java:51)
    ...

Recommended usage of Copyartifact

  • Artifacts should be stored as archived files.
    • Copyartifact tries to copy artifacts preserving file attributes like permissions and symbolic links. Though, it may fail in some situations (like for security issues).
    • It's highly recommended to pack files to copy into an archive file, using tar command or zip pipeline step, especially when it's important for you to preserving file attributes or directory structures.

Permissions to copy artifact

When you face a following message and fail to copy artifacts, this may be caused by permission to the project with artifacts. Please read this section once.

Unable to find project for artifact copy: YOUR_PROJECT_WITH_ARTIFACTS
This may be due to incorrect project name or permission settings; see help for project name in job configuration.
Build step 'Copy artifacts from another project' marked build as failure

Specifying project statically (without variables)

  • This case:
  • In this case, you can copy artifacts if you have permission to read the project to copy from at configuration time.

Specifying project dynamically (with variables)

  • Those cases:

  • If your Jenkins is secured, it fails to copy artifacts without a proper configuration.
  • You need to allow projects copy artifacts in one of following ways:

Allow read from anonymous

  • Copyartifact plugin treats builds running as an anonymous.
  • Copying artifacts is allowed if the project with artifacts is readable from anonymous.
  • When you use Matrix-based security for authorization, it can be done as following in Manage Jenkins > Global Security Configuration:
  • When you use Project-based Matrix Authorization Strategy for authorization, it can be done as following in the configuration page of the project to copy artifacts from:

Specify projects who can copy artifacts

  • Available since Copyartifact 1.30
  • In the project configuration pages, you can specify projects to allow copy artifacts from that project:
  • You can specify multiple projects with separating with commas.
  • You can use wildcard character ('*') to specify name patterns.

Since Copyartifact 1.30, there is a limitation "Permission to Copy Artifacts" accepts only relative project names.
If you use CloudBees Folders Plugin and the projects are located in different folders, you need to specify project names like "../folder/project".
This is fixed in Copyartifact 1.31.

Authorize builds as a user

  • Available since Jenkins 1.532
    • To be exact, the feature of Jenkins to authorize builds are available since 1.520, but who cares such details?
  • Authorize Project plugin enables you to run builds of a project as a specific user.
    • Copyartifact plugin treats builds running as an anonymous without authorization configurations.
  • You can resolve permission problems by running builds as a user with read permission to the project with artifacts


Use with declarative pipelines

One example: 

stages {
    stage('Copy Archive') {
        steps {
            script {
                step ([$class: 'CopyArtifact',
                projectName: 'Create_archive',
                filter: "packages/infra*.zip",
                target: 'Infra']);
            }
        }
    }

What that is doing: 

  • Go to the project/workspace named "Create_archive".
  • Look in the folder "packages" for the file(s) "infra*.zip".
  • Copy that file(s) into the folder "Infra", in the local workspace.  Folder will be created if it doesn't already exist.




Issues

To report a bug or request an enhancement to this plugin please create a ticket in JIRA (you need to login or to sign up for an account). Also have a look on How to report an issue

Key T P Summary
JENKINS-65138 Bug Major Copy Artifacts from MultiBranch pipeline fails to find build with specified parameters
JENKINS-63866 Bug Minor Permission to copy from the job itself should not be needed
JENKINS-61407 Improvement Minor Provide boolean response of copyArtifacts
JENKINS-60097 Improvement Minor Copying artifacts should offer to link them, if possible
JENKINS-57346 Epic Minor plugins should not rely on help from jenkins core
JENKINS-56459 Bug Minor Cannot copy artifact from project with a "," in the name
JENKINS-56451 New Feature Minor Copy artifacts from multiple builds
JENKINS-55259 Improvement Minor Copyartifact plugin requires Matrix Project plugin
JENKINS-51482 Improvement Minor Allow multiple specific builds
JENKINS-50545 New Feature Minor Add keep forever option
JENKINS-49090 Bug Major Cannot specify a build with parameters containing hyphen("-")
JENKINS-48339 Bug Minor Copy artifacts from upstream: Unable to find project for artifact copy
JENKINS-47916 Improvement Minor Specific build selector should take ints
JENKINS-42587 Bug Minor Unable to copy artifacts from sibling of MultiJob project
JENKINS-41529 New Feature Minor Rebuilder support by copyartifact
JENKINS-40549 Bug Minor Unable to use Parameter filters in copy artifacts if parameter values contain commas
JENKINS-40429 Bug Blocker Copy artifacts from multi-branch pipeline project with project name as a build parameter fails with "Unable to find project for artifact copy"
JENKINS-38554 New Feature Minor CopyArtifactPlugin does not allow for multiple upstream projects
JENKINS-34624 Bug Minor Copy Artifact to node on same machine as master broken
JENKINS-34620 New Feature Minor COPYARTIFACT_BUILD_NUMBER_SUFFIX for pipelines (aka. workflow jobs)
JENKINS-33680 New Feature Minor Add option to copy console build log
JENKINS-31537 Improvement Minor Copy Artifact from Promoted Matrix Configuration
JENKINS-30428 New Feature Minor Would like to use CopyArtifact to drive other actions
JENKINS-28206 Improvement Major Build selector "Downstream build of" should be usable as parameter or source filter
JENKINS-28184 Improvement Minor Copy artifacts from all "Downstream build of"
JENKINS-28109 Improvement Minor Local artifact cache on slaves
JENKINS-26803 New Feature Minor Copy artifacts from a different master
JENKINS-26802 New Feature Minor Copying artifacts from many projects
JENKINS-26697 Improvement Minor Log message to console to indicate copying has started
JENKINS-24152 New Feature Major New Build trigger that fires when builds of projects to copy from finished
JENKINS-23976 Improvement Major CopyArtifact plugin does not like incorrect build selector.
JENKINS-22480 New Feature Minor option to check file checksums after copying artfacts
JENKINS-20814 Improvement Major Copy only the changes to (sync) the artifacts
JENKINS-20680 Improvement Minor Remote triggering "Copy Artifact" build selector requires weird syntax
JENKINS-20508 New Feature Minor Select a build via SVN revision
JENKINS-20451 Improvement Major Add Copy Artefacts info to the xml Rest API
JENKINS-20370 Improvement Major CopyArtifact - get last artifact from self
JENKINS-17570 New Feature Major not copying artfacts from another job using specifc build number passed by environment variable.
JENKINS-17538 Improvement Minor When artifact is copied, add an Action to track the build this artifact has been copied for
JENKINS-16987 Bug Minor Path of fingerprinted files not saved by CopyArtifacts
JENKINS-16847 New Feature Major Support for copying artifacts from other builds being part of the same MultiJob (previous phases)
JENKINS-16405 New Feature Major suppert basedir, The basedir configuration is similar to the ArtifactDeployer plug-in provides
JENKINS-16139 Bug Major Copy Artifacts of specific build number fails if build is triggered by upstream project.
JENKINS-16108 New Feature Major Option to use "last unstable" as fallback for "Upstream build which trigger" instead of only "last successful"
JENKINS-14962 Bug Major Failure to copy artifacts from Master job to slave job
JENKINS-13488 Improvement Major Copy Artifacts plugin's "Optional" not working
JENKINS-13388 New Feature Major Add option to delete existing artifacts before copy
JENKINS-12974 Improvement Minor Use hard links if possible, for local copies
JENKINS-12379 Improvement Major Archive the artifacts should allow specifying the target artifacts path
JENKINS-12064 Improvement Critical Disable copy artifact for modules
JENKINS-11629 Improvement Minor Request ability to list project builds by description in dropdown.
JENKINS-11336 Improvement Major Copy artifacts task should should give more info in console before performing the action
JENKINS-11133 Improvement Major Copy artifacts from specific matrix configuration does not check stability of entire matrix
JENKINS-10861 New Feature Minor Copy artifacts from downstream job run via synchronous Trigger Build step
JENKINS-9709 New Feature Minor Feature to copy artifact from different upstream projects
JENKINS-9622 New Feature Major Add build selector to parameterized trigger
JENKINS-9593 Improvement Major Copy artifact fails when slave is offline
Authenticate to retrieve your issues


Change Log

Version 1.43 (Oct 5, 2019)
  • Support buildSelector  in pipeline parameters (#114)
Version 1.42.1 (May 25, 2019)
  • Improved documents.
    • Improve help texts of project names. (#107)
    • Fix spelling errors. (#112)
  • Removed scm-api plugin from dependencies.
Version 1.42 (Mar 02, 2019)
  • Introduce a new selector: Last build with artifacts (  JENKINS-35417 - Support "last exist" condition. Closed )
Version 1.41 (Jun 30, 2018)
  • copyArtifactPermission support:
    • Declarative pipeline:

      pipeline {
          agent any;
          options {
              copyArtifactPermission('job1,job2,...');
          }
          stages{...}
      }
    • Scripted pipeline

      properties([
          copyArtifactPermission('job1,job2,...'),
      ]);
      node {
          ...
      }
  • Retries downloading artifacts from ArtifactManagers supporting the external URL feature like Artifact Manager S3 Plugin .
    • You MUST upgrade copyartifact from 1.40 if you use Artifact Manager S3 Plugin (or plugins providing the external URL feature for artifacts) and the upcoming version of Jenkins (might be 2.130).
Version 1.40 (May 13, 2018)
  • Targets Jenkins 2.118

    • There're no LTS yet, please consider to use copyartifact-1.40-beta-1 if you use LTS.

      • Be careful that 1.40-beta-1 doesn't support the exclude filter.

  • ArtifactManager support (JENKINS-22637)
Version 1.40-beta-1 (Apr 29, 2018)
Version 1.39.1 (Apr 1, 2018)
  • Simple arguments for upstream selector (TriggeredBuildSelector)
Version 1.39 (Oct 29, 2017)
Version 1.38.1 (Jul 24, 2016)
  • Fixed: symlinks aren't created (JENKINS-32832)
    • It occurred when symlinks are placed in subdirectories.
  • Fixed: Empty variables aren't replaced to empty strings. (JENKINS-36554)
Version 1.38 (Apr 17, 2016)
Version 1.37 (Oct 4, 2015)
  • Added an option to 'Upstream build that triggered this job' to allow upstream dependencies (#73).
Version 1.36.1 (Nov 4, 2015)
  • Fixed problems with "Specified by a build parameter" (JENKINS-30357)
    • Fixed NPE when specified undefined variables.
    • Supports used in workflow jobs.
    • Also supports immediate value specification for used in workflow jobs (${SELECTOR} in workflow jobs).
    • Also supports variable expression (${SELECTOR} in non-workflow jobs).
Version 1.36 (Sep 6, 2015)
  • Introduced a field to specifi the suffix of the variable to store the build number. (JENKINS-18938, JENKINS-29812)
    • Added "Result variable suffix" in the "advanced" section.
    • It allows you to store the build number to the variable named "COPYARTIFACT_BUILD_NUMBER_(specified name)"
    • Copyartifact behaves as before (creates the suffix from the source project name) if you don't specified it. You don't need to reconfigure existing configurations.
Version 1.35.2 (Jul 4, 2015)
Version 1.35.1 (May 10, 2015)
Version 1.35 (Mar 1, 2015)
Version 1.34 (Jan 25, 2015)
Version 1.33 (Jan 17, 2015)
  • Added a new build selector "last completed build" (JENKINS-16476)
Version 1.32.1 (Oct 20, 2014)
  • Fixed NPE when used in promotions (Promoted Builds plugin) (JENKINS-25155).
Version 1.32 (Oct 12, 2014)
  • Added a new build selector "Downstream build of" (JENKINS-24626)
  • Fixed NPE on TriggeredBuildSelector when the upstream is removed. (JENKINS-18804)
  • Fixed COPYARTIFACT_BUILD_NUMBER_XXX not declared in some cases
  • TriggeredBuildSelector is now applicable also for maven module builds (JENKINS-14653)
Version 1.31 (Jul 21, 2014)
  • Supports absolute paths in CopyArtifactPermissionProperty. (JENKINS-22038)
  • Fixed input validation problem when used with Cloudbees Template and Cloudbees Folders plugin (JENKINS-22828)
  • Fixed: Promotion permalinks not offered when job name is parameterized (JENKINS-22590)
  • Fixed: Name of COPYARTIFACT_BUILD_NUMER_ variable is incorrectly documented (JENKINS-15764)
  • Fixed: Project source of a multi-config project inside a folder not working (JENKINS-20940)
  • Added a parameter to specify whether to copy from the newest upstream or the oldest one when triggered by multiple upstreams. (JENKINS-11655)
  • Fixed: Copying from workspace drops files matching Ant's default excludes (JENKINS-14900)
    • *Specify explicitly files matching Ant's default excludes with "Artifacts not to copy" if you need to exclude them.
  • Added exclude filter. (JENKINS-18662)
  • Fixed inproper help texts of filter. Copyartifact doesn't fail even specified files don't really exist. (JENKINS-23444)
Version 1.30 (Feb 16, 2014)
  • Added license information (MIT).
  • Fixed ClassNotFound when maven plugin not installed (JENKINS-15977)
  • Allow to specify named builds in Specific Build Selector (JENKINS-19693)
  • Job Property to define projects that can copy artifacts (JENKINS-20398)
  • Fixed startup failure without maven-plugin (JENKINS-21274)
Version 1.29 (Jan 29, 2014)
  • Support (mostly) absolute path for job name
    i.e. job name can be fully qualified but not start with "/"
    required for backward compatibility (JENKINS-19833)
  • The authorization of builds are considered (when used with QueueItemAuthenticator). QueueItemAuthenticator is available from Jenkins 1.520. (JENKINS-14999)
  • Make fingerprinting artifacts optional. By default the old behavior is preserved. (JENKINS-12134 and this serves as a workaround for JENKINS-17606).
Version 1.28 (Sep 23, 2013)
  • Supports ItemGroup (Cloudbees folders)
  • Added diagnostics log messages when using SpecificBuildSelector (related to JENKINS-18220)
  • Migrates configuration when upgraded from version 1.25 or earlier. (JENKINS-17680)
Version 1.27 (May 01, 2013)
  • NPE renaming job after 1.26 format change. (JENKINS-17447)
  • Optional Copy Artifact build step fails if no specific build's build number is given. (JENKINS-14266)
Version 1.26 (Mar 25, 2013)
  • Split filtering by build parameters into a separate configuration field, solving a security problem related to job configuration and upstream builds. Existing job configuration using this plugin will be rewritten if you run at least one build after the upgrade; if you immediately open the configuration page you will need to manually restore the upstream project field. (JENKINS-13222)
  • Gets artifacts from jobs higher in the upstream chain. (pull request #18)
Version 1.25 (Nov 06, 2012)
Version 1.24 (Oct 03, 2012)
  • Continued fix for the case of a Windows slave with Unix master. (JENKINS-13515)
Version 1.23 (Sep 21, 2012)
  • Failure on some Windows machines introduced in 1.22. (JENKINS-13515)
Version 1.22 (Apr 16, 2012)
  • Hierarchical project support.
Version 1.21 (Jan 12, 2012)
  • Revisited JENKINS-12134 implementation to hide the computation overhead to the actual copy operation.
Version 1.20 (Dec 16, 2011)
Version 1.19 (Nov 28, 2011)
  • Using "Upstream build which triggered" with "Last successfull" fallback uses last build as fallback and not last successful. (JENKINS-11828)
  • Improve a misleading error message. (JENKINS-10762)
  • Added hyperlinks to console output
  • Added german translation
Version 1.18 (Jul 24, 2011)
  • Copy only artifacts run for a particular matrix build (not those inherited from previous builds) in Jenkins 1.413+. (JENKINS-10214)
Version 1.17 (Jul 24, 2011)
  • Add support for multiconfiguration(matrix) projects with upstream build selector. (JENKINS-9729)
  • Add an option for upstream build selector to use last successful build when job is not triggered by upstream job. (JENKINS-10225)
  • Partial fix for JENKINS-9741 to preserve permissions on the copied artifacts when using the "flatten" option.
Version 1.16 (Apr 17, 2011)
  • Add build selector to select the upstream build that triggered this job. (JENKINS-8999)
  • Avoid NullPointerException triggered by Build Pipeline Plugin. (JENKINS-9359)
  • Allow filters in project name field to match all build variables, not just parameters. (JENKINS-9327)
    Compatibility Note: More variables are now matched, but values for boolean parameters must now be specified as true and false (previously yes/no, on/off and 1/0 were also accepted).
  • Make text field for project name wider. (JENKINS-9373)
  • Investigated permissions problem with using parameters to select a particular matrix configuration or maven module; this is fixed in Jenkins core 1.406. (JENKINS-9293)
Version 1.15 (Apr 11, 2011)
  • Add note in "project not found" console message that error may be due to permission settings as well as invalid name.
  • Removed workaround code for JENKINS-5977 now that minimum required Jenkins version for this plugin has that issue fixed.
  • Updates for Jenkins
Version 1.14 (Feb 24, 2011)
  • Rerelease 1.13 to properly set required Jenkins version.
Version 1.13 (Feb 10, 2011)
  • Prevent access to artifacts of private jobs. (JENKINS-8727)
    • For a fixed project name, check at save-config time and disallow use of jobs the current user cannot see.
    • For parameterized names, check at build time that the source job is accessible to all authenticated users.
  • Record build number of selected build into environment for later build steps to reference. More detail in help text for build selector. (JENKINS-8722)
  • Add support for filtering on build parameters, such as "latest stable build with parameter FOO=bar". More detail in help text for project name. (JENKINS-8657)
Version 1.12 (Jan 30, 2011)
  • Restore ability to copy artifacts from a maven project that were archived with a post-build step (instead of maven automatic archiving). (JENKINS-7752)
Version 1.11 (Nov 7, 2010)
  • Copy artifacts from all modules/configurations when a maven/matrix project is selected. (JENKINS-7752)
  • Add extension point for how files are copied from source to target, allowing other plugins to override default implementation using Jenkins' FilePath class. (JENKINS-7753)
  • Add note about limitation in copy-from-workspace feature. (JENKINS-7751)
Version 1.10 (Oct 10, 2010)
  • Add option to copy from workspace of latest completed build. (JENKINS-7130)
    Note: source and target jobs cannot both run on slave nodes; at least one must be on the master node.
  • Strip newlines in XML form of build selector parameters, to avoid breaking ant execution on windows. (JENKINS-7680)
Version 1.9 (Sep 28, 2010)
  • Now supports selecting a build based on its permalink, which allows this plugin to work nicely with the promoted builds plugin.
Version 1.8 (Jul 18, 2010)
  • Add parameter expansion in selecting a specific build number. (JENKINS-6972)
Version 1.7 (May 12, 2010)
  • Add support for using a build parameter to specify the BuildSelector used for copying artifacts.
Version 1.6 (May 8, 2010)
  • Make build environment available to BuildSelectors.
Version 1.5 (May 5, 2010)
  • Add Japanese localization.
Version 1.3 (May 2, 2010)
  • Add option to flatten directories when copying, so all artifacts from source project are copied directly into target directory. (JENKINS-6345)
  • Add option to make the copy optional, so build doesn't fail if build, workspace, or matching artifact is not found. This release changes the default behavior when build is found but no artifacts were copied (now a build failure, previously just reported "0 files copied").
  • Add some help text about copying artifacts from Maven modules. (JENKINS-6355)
Version 1.2 (Apr 17, 2010)
  • Add parameter expansion in name of project to copy from and add some help text about copying from matrix jobs. (JENKINS-6242)
  • Add extension point for how to select which build to copy artifacts from. Includes selectors for latest successful/stable build or latest saved ("keep forever") build.
    Other plugins known to implement this extension: Promoted Builds Simple Plugin
Version 1.1 (Mar 18, 2010)
Version 1.0 (Mar 7, 2010)
  • Initial release.