Optimize Your CI/CD Pipeline
Get instant insights into your CI/CD performance and costs. Reduce build times by up to 45% and save on infrastructure costs.
jenkins-plugin-cli --plugins copyartifact:722.v0662a_9b_e22a_c
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.
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
Parameter | Type | Description |
---|---|---|
projectName | string | The name of project (required) |
selector | BuildSelector | The selector to select the build to copy from. If not specified, latest stable build is used. |
parameters | string | Comma-separated name and value pairs (name1=value1,name2=value2) to filter the build to copy from. |
filter | string | Ant-expression to filter artifacts to copy |
excludes | string | Ant-expression to exclude artifacts to copy |
target | string | Target directory to copy to |
flatten | boolean | Ignore directory structures of artifacts |
optional | boolean | Do not fail the step even if no appropriate build is found |
fingerprintArtifacts | boolean | Fingerprint 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). |
resultVariableSuffix | boolean | Useless for pipelines |
includeBuildNumberInTargetPath | boolean | Include source build number in target path |
Selectors
Name | Feature |
---|---|
lastSuccessful | Latest successful build |
specific | Specific build |
permalink | Specified by permalink |
lastCompleted | Completed build (ignoring build status) |
latestSavedBuild | Latest saved build (marked "keep forever") |
buildParameter | Specified by a build parameter |
upstream | Upstream build that triggered this job |
Recommended usage
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.