📖 Scenario: You work in a software team that builds applications using Jenkins. Each build creates files called artifacts, like compiled programs or packages. Managing these artifacts well helps your team keep track of versions, share files easily, and avoid mistakes.
🎯 Goal: Learn how to create a simple Jenkins pipeline that saves build artifacts and then lists them. This shows why storing and managing artifacts is important in real projects.
📋 What You'll Learn
Create a Jenkins pipeline script with a build stage
Save a sample artifact file using the archiveArtifacts step
Add a step to list saved artifacts
Print the artifact names to show they are stored
💡 Why This Matters
🌍 Real World
In real software projects, managing build artifacts helps teams share and reuse files, track versions, and avoid rebuilding unnecessarily.
💼 Career
Understanding artifact management is key for DevOps roles using Jenkins or other CI/CD tools to ensure reliable and efficient software delivery.
Progress0 / 4 steps
1
Create a sample artifact file
In the Jenkins pipeline script, inside the stage('Build'), create a file named sample.txt with the content 'This is a build artifact.' using the writeFile step.
Jenkins
Hint
Use writeFile to create a file with the given name and content.
2
Archive the artifact file
Add a step inside the stage('Build') to archive the file sample.txt using the archiveArtifacts step.
Jenkins
Hint
Use archiveArtifacts with the artifacts parameter set to the file name.
3
List archived artifacts
Add a new stage('List Artifacts') after the Build stage. Inside it, add a steps block with a sh command to list files in the current directory using ls -l.
Jenkins
Hint
Use stage to add a new stage and sh 'ls -l' to list files.
4
Print artifact file name
Add a stage('Show Artifact Name') after List Artifacts. Inside it, add a steps block with a script that uses echo to print 'Artifact stored: sample.txt'.
Jenkins
Hint
Use echo inside steps to print the message.
Practice
(1/5)
1. Why is artifact management important in Jenkins pipelines?
easy
A. It automatically deletes all build files after each run.
B. It saves build files for reuse and sharing across jobs.
C. It slows down the build process by adding extra steps.
D. It only works with Docker containers, not regular files.
Solution
Step 1: Understand artifact management purpose
Artifact management stores build outputs so they can be reused without rebuilding.
Step 2: Identify correct Jenkins behavior
Jenkins pipelines use artifact management to save and share files, improving efficiency.
Final Answer:
It saves build files for reuse and sharing across jobs. -> Option B
Quick Check:
Artifact management = saves and shares files [OK]
Hint: Artifacts store build files for reuse, not deletion [OK]
Common Mistakes:
Thinking artifacts delete files after build
Believing artifact management slows builds
Assuming artifacts only work with Docker
2. Which Jenkins pipeline step syntax correctly archives artifacts?
easy
A. archiveArtifacts 'build/output/*.jar'
B. archive 'build/output/*.jar'
C. saveArtifacts 'build/output/*.jar'
D. storeArtifacts 'build/output/*.jar'
Solution
Step 1: Recall Jenkins pipeline syntax
The correct step to archive artifacts is archiveArtifacts.
Step 2: Match syntax with options
Only archiveArtifacts 'build/output/*.jar' uses the exact Jenkins step archiveArtifacts with correct string pattern.
Final Answer:
archiveArtifacts 'build/output/*.jar' -> Option A
Quick Check:
Correct step is archiveArtifacts [OK]
Hint: Use archiveArtifacts to save files in Jenkins [OK]
Common Mistakes:
Using archive instead of archiveArtifacts
Using saveArtifacts or storeArtifacts which don't exist
Missing quotes around file pattern
3. What will Jenkins display after running this pipeline snippet?