0
0
Jenkinsdevops~10 mins

Copying artifacts between jobs in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Copying artifacts between jobs
Job A builds and archives artifact
Artifact stored in Jenkins
Job B triggers or waits
Job B copies artifact from Job A
Job B uses artifact for its build
This flow shows how one Jenkins job creates and stores an artifact, and another job copies that artifact to use it.
Execution Sample
Jenkins
pipeline {
  agent any
  stages {
    stage('Copy Artifact') {
      steps {
        copyArtifacts(projectName: 'JobA', filter: 'output/*.jar')
      }
    }
  }
}
This Jenkins pipeline (Job B) copies artifacts from Job A. Job A archives them using `archiveArtifacts artifacts: 'output/*.jar'`.
Process Table
StepActionJobArtifact StateResult
1Build completes and archives artifactJob AArtifact 'app.jar' savedArtifact stored in Jenkins
2Job B starts and calls copyArtifactsJob BNo artifact yetStarts copying
3copyArtifacts fetches 'app.jar' from Job AJob BArtifact copied locallyArtifact ready for use
4Job B uses artifact in buildJob BArtifact presentBuild proceeds with artifact
5Job B finishesJob BArtifact usedJob B completes successfully
💡 Job B finishes after copying and using artifact from Job A
Status Tracker
VariableStartAfter Step 1After Step 3Final
artifact_locationnonestored in Jenkins archivecopied to Job B workspacepresent in Job B workspace
Key Moments - 2 Insights
Why does Job B need to specify the projectName in copyArtifacts?
Because copyArtifacts needs to know which job's artifacts to copy. This is shown in execution_table step 3 where Job B fetches artifacts from Job A.
What happens if Job A has not archived any artifacts?
copyArtifacts will fail to find artifacts to copy, so Job B cannot proceed with the artifact-dependent build. This is implied by the artifact state in step 2 and 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does Job B have the artifact copied locally?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Check the 'Artifact State' column in execution_table row for Step 3.
According to variable_tracker, what is the state of artifact_location after Step 1?
Anone
Bstored in Jenkins archive
Ccopied to Job B workspace
Dpresent in Job B workspace
💡 Hint
Look at the 'After Step 1' column for artifact_location in variable_tracker.
If Job A does not archive artifacts, what will happen in Job B's copyArtifacts step?
AcopyArtifacts will fail to find artifacts
BcopyArtifacts will succeed with empty files
CJob B will skip copying and continue
DJob B will archive artifacts instead
💡 Hint
Refer to key_moments explanation about missing artifacts and execution_table steps 2 and 3.
Concept Snapshot
Jenkins jobs can share files by archiving artifacts in one job and copying them in another.
Use archiveArtifacts in the producing job.
Use copyArtifacts with projectName and filter in the consuming job.
Artifacts are stored centrally and copied on demand.
This enables multi-job pipelines sharing build outputs.
Full Transcript
In Jenkins, one job can save files called artifacts using archiveArtifacts. Another job can copy these files using copyArtifacts by specifying the job name and file pattern. The flow starts with Job A building and archiving the artifact. Then Job B runs and copies the artifact from Job A's archive. This allows Job B to use the artifact in its build. If Job A does not archive artifacts, Job B's copyArtifacts step will fail. Tracking the artifact location shows it moves from Jenkins storage to Job B's workspace. This method helps share build outputs between jobs in Jenkins pipelines.