Consider this Jenkins pipeline stage that copies artifacts from a previous job named BuildJob:
stage('Copy Artifacts') {
steps {
copyArtifacts(projectName: 'BuildJob', selector: lastSuccessful())
}
}What happens when this stage runs?
stage('Copy Artifacts') { steps { copyArtifacts(projectName: 'BuildJob', selector: lastSuccessful()) } }
Think about what lastSuccessful() means in Jenkins.
The copyArtifacts step with lastSuccessful() selector copies artifacts from the last successful build of the specified project into the current job's workspace.
You want to copy artifacts from build number 42 of the job named TestJob. Which snippet does this correctly?
Look for the correct selector method for a specific build number.
The specific('42') selector is the correct way to specify a particular build number as a string in copyArtifacts.
Given this pipeline snippet:
stage('Copy') {
steps {
copyArtifacts(projectName: 'NonExistentJob', selector: lastSuccessful())
}
}The pipeline fails with an error about missing artifacts. What is the most likely cause?
Check if the source job exists and has successful builds.
If the source job does not exist or has no successful builds, copyArtifacts cannot find artifacts to copy, causing failure.
Arrange these steps in the correct order to copy artifacts from a build stage to a deploy stage within the same pipeline:
Think about preparing workspace, building, copying, then deploying.
First clean workspace, then build and archive artifacts, then copy artifacts, finally deploy.
Choose the best practice to avoid failures when copying artifacts between jobs in Jenkins pipelines.
Think about what makes artifacts available for copying.
Artifacts must be archived in the source job to be available for copying. Without archiving, copying fails.