Skip to main content
← Back to workflows

How to Copy Files Between Jenkins Projects?

copyartifact -
Jenkins Plugin
v.722.v0662a_9b_e22a_c
62
Required Jenkins: v.2.414.3
ID: copyartifact
Contributors
Contributor - ikedamContributor - alanharderContributor - jglick
Categories
CICUBE ANALYTICS INSIGHTS
Engineering Velocity: 25% Team Time Lost to CI Issues
View Platform →
3.5h
Time Saved/Dev/Week
40%
Faster Releases
Click for next insight
Installation with the CLI tool
jenkins-plugin-cli --plugins copyartifact:722.v0662a_9b_e22a_c

copyartifact-plugin logo

Copy Artifact

Copy Artifact Plugin simplifies transferring artifacts between Jenkins projects, offering flexible options.


What is Copy Artifact Plugin?

The Copy Artifact Plugin extends Jenkins functionality by enabling users to copy artifacts from one project to another as a build step. This streamlines the process of sharing and utilizing artifacts across Jenkins jobs.

This plugin provides a straightforward method to specify the source build from which artifacts should be copied. Users can choose from options such as the last successful or stable build, a specific build number, or a build parameter. Additionally, users have granular control over the copying process, including filtering files, defining destination directories within the target project, and more.

The plugin offers detailed documentation accessible via the help icon for each field, assisting users in configuring settings for Maven projects, multiconfiguration projects, and utilizing build parameters effectively. Moreover, users have the option to copy artifacts directly from the workspace of the latest completed build of the source project, bypassing the need to archive artifacts explicitly.

All copied artifacts are automatically fingerprinted, enhancing traceability and facilitating artifact management across Jenkins pipelines.

What is Copy Artifact Plugin

How to Use Copy Artifact Plugin?

Pipeline syntax

  • To Copy Artifacts from the Latest Stable Build of "sourceproject":
copyArtifacts(projectName: 'sourceproject');
  • To Copy Artifacts from a Specific Build of "downstream":
def built = build('downstream');
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. False for default if the parameter isn't specified (Snippet Generator defaults this to true and specifies the parameter).
resultVariableSuffixbooleanUseless for pipelines
includeBuildNumberInTargetPathbooleanInclude source build number in target path

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

For optimal functionality, it's best to store artifacts as archived files.

Copyartifact endeavors to maintain file attributes such as permissions and symbolic links during artifact copying. However, it may encounter challenges in certain scenarios, particularly those related to security.

To ensure smooth operation and avoid potential issues, it's strongly advised to bundle files intended for copying into an archive file. This can be achieved using the tar command or the zip pipeline step. This approach is particularly crucial when preserving file attributes or directory structures is a priority.

By archiving files before copying, you enhance the reliability and consistency of artifact transfer operations, minimizing the risk of unexpected complications during the copying process.