0
0
Jenkinsdevops~10 mins

Archiving artifacts in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Archiving artifacts
Build completes
Identify artifacts
Archive artifacts step
Artifacts saved in Jenkins
Artifacts available for download or later stages
After a build finishes, Jenkins identifies files to save, archives them, and makes them available for later use.
Execution Sample
Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        sh 'echo Hello > output.txt'
      }
    }
    stage('Archive') {
      steps {
        archiveArtifacts artifacts: 'output.txt'
      }
    }
  }
}
This Jenkins pipeline creates a file and archives it as a build artifact.
Process Table
StepActionFile CreatedArchive StepArtifacts Stored
1Start buildNoNoNo
2Run shell command: echo Hello > output.txtoutput.txt createdNoNo
3Archive artifacts: output.txtoutput.txt existsArchive triggeredoutput.txt saved
4Build completeoutput.txt existsArchivedArtifacts available
💡 Build finishes with output.txt archived as artifact
Status Tracker
VariableStartAfter Step 2After Step 3Final
output.txt fileNot presentCreatedArchivedArchived and available
Key Moments - 2 Insights
Why do we need to archive artifacts after the build?
Archiving saves important files like logs or binaries so they can be accessed later, as shown in step 3 of the execution_table.
What happens if the file to archive does not exist?
The archive step will fail because Jenkins cannot find the file, so ensure the file is created before archiving, as seen between steps 2 and 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step is the artifact actually saved?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Check the 'Archive Step' and 'Artifacts Stored' columns in the execution_table at step 3.
According to variable_tracker, what is the state of output.txt after step 2?
ANot present
BCreated
CArchived
DDeleted
💡 Hint
Look at the 'After Step 2' column for output.txt file in variable_tracker.
If the shell command did not create output.txt, what would happen at step 3?
AArchive step would fail
BArchive step would succeed anyway
CBuild would skip archive step
DFile would be created automatically
💡 Hint
Refer to key_moments about missing files before archiving.
Concept Snapshot
Jenkins archiving artifacts:
- After build, specify files to save
- Use archiveArtifacts step with file pattern
- Files saved with build for download or later use
- Fails if files missing
- Helps keep build outputs safe
Full Transcript
In Jenkins, archiving artifacts means saving files created during a build so they can be accessed later. The process starts after the build finishes. Jenkins looks for files you specify, like output.txt, and saves them with the build record. This is done using the archiveArtifacts step in the pipeline. If the file does not exist, the archive step will fail. Archiving is useful to keep logs, binaries, or reports safe and available for download or use in later pipeline stages.