0
0
Jenkinsdevops~30 mins

Archiving artifacts in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Archiving Artifacts in Jenkins Pipeline
📖 Scenario: You are working on a Jenkins pipeline that builds a simple project. After the build, you want to save the build output files so they can be accessed later. This is called archiving artifacts.Archiving artifacts helps keep important files safe and shareable after the build finishes.
🎯 Goal: Build a Jenkins pipeline script that archives the output.log file after the build step.
📋 What You'll Learn
Create a Jenkins pipeline script with a pipeline block
Add a stage named Build that creates a file output.log
Add a stage named Archive that archives the output.log file using archiveArtifacts
💡 Why This Matters
🌍 Real World
Archiving artifacts in Jenkins pipelines is essential for saving build outputs like logs, binaries, or reports. These files can be downloaded later or used in deployment steps.
💼 Career
Understanding artifact archiving is a key skill for DevOps engineers and CI/CD pipeline developers to ensure build results are preserved and traceable.
Progress0 / 4 steps
1
Create the Jenkins pipeline skeleton
Write a Jenkins pipeline script starting with pipeline and agent any. Add a stage named Build with a steps block that creates a file called output.log containing the text Build successful using the shell command sh.
Jenkins
Need a hint?

Use sh 'echo Build successful > output.log' inside the steps block to create the file.

2
Add the Archive stage
Add a new stage named Archive after the Build stage. Inside its steps block, prepare to archive the file output.log using the archiveArtifacts step.
Jenkins
Need a hint?

Add a new stage('Archive') with a steps block inside stages.

3
Archive the output.log file
Inside the Archive stage's steps block, write the command archiveArtifacts artifacts: 'output.log' to archive the file output.log.
Jenkins
Need a hint?

Use archiveArtifacts artifacts: 'output.log' to save the file as an artifact.

4
Print confirmation message
Add a stage named Confirm after Archive. Inside its steps block, write echo 'Artifacts archived successfully.' using the sh step to print a confirmation message.
Jenkins
Need a hint?

Use sh 'echo Artifacts archived successfully.' inside the Confirm stage to print the message.