0
0
Jenkinsdevops~30 mins

Copying artifacts between jobs in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Copying Artifacts Between Jenkins Jobs
📖 Scenario: You are working on a Jenkins pipeline where you need to build a project in one job and then use the build output (artifact) in another job. This is common when you want to separate build and deployment steps into different jobs.
🎯 Goal: Build a Jenkins pipeline script that copies an artifact from one job to another using the copyArtifacts plugin step.
📋 What You'll Learn
Create a Jenkins pipeline script with two stages: Build and Deploy
In the Build stage, create a file named app.jar as a dummy artifact
Archive the app.jar file as an artifact in the Build stage
In the Deploy stage, copy the artifact app.jar from the Build stage using copyArtifacts
Print a message confirming the artifact was copied
💡 Why This Matters
🌍 Real World
In real projects, build and deployment are often separated into different jobs. Copying artifacts lets you reuse build outputs without rebuilding.
💼 Career
DevOps engineers and Jenkins administrators frequently use artifact copying to create efficient CI/CD pipelines.
Progress0 / 4 steps
1
Create the Build stage with artifact
Create a Jenkins pipeline script with a Build stage that creates a file named app.jar containing the text "dummy artifact" and archives it using archiveArtifacts.
Jenkins
Need a hint?

Use writeFile to create the file and archiveArtifacts to save it as an artifact.

2
Add Deploy stage with copyArtifacts configuration
Add a Deploy stage to the pipeline that uses copyArtifacts to copy the artifact app.jar from the Build stage.
Jenkins
Need a hint?

Use copyArtifacts with projectName: env.JOB_NAME and selector: lastSuccessful() to copy from the same job's last successful build.

3
Add a step to confirm artifact copy
Inside the Deploy stage, add a sh step to list the files in the workspace to confirm that app.jar was copied.
Jenkins
Need a hint?

Use sh 'ls -l' to list files in the workspace.

4
Print confirmation message after copying artifact
Add a echo step inside the Deploy stage after copying the artifact to print "Artifact app.jar copied successfully".
Jenkins
Need a hint?

Use echo 'Artifact app.jar copied successfully' to print the confirmation message.