Archiving artifacts in Jenkins - Time & Space Complexity
When Jenkins archives artifacts, it saves files from a build for later use. Understanding how the time to archive grows helps us plan for bigger projects.
We want to know: how does archiving time change as the number of files or their size increases?
Analyze the time complexity of the following Jenkins pipeline snippet.
pipeline {
agent any
stages {
stage('Build') {
steps {
// build steps here
}
}
stage('Archive') {
steps {
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
}
}
}
}
This code archives all .jar files found under any target folder after the build finishes.
Look for repeated actions that affect time.
- Primary operation: Scanning the workspace to find matching files and copying each file to the archive storage.
- How many times: Once per file found matching the pattern; each file is processed individually.
As the number of files grows, the time to archive grows too.
| Input Size (n files) | Approx. Operations |
|---|---|
| 10 | About 10 file scans and copies |
| 100 | About 100 file scans and copies |
| 1000 | About 1000 file scans and copies |
Pattern observation: The time grows roughly in direct proportion to the number of files.
Time Complexity: O(n)
This means if you double the number of files, the archiving time roughly doubles too.
[X] Wrong: "Archiving time stays the same no matter how many files there are."
[OK] Correct: Each file must be found and copied, so more files mean more work and more time.
Knowing how archiving scales helps you understand build pipelines better. It shows you how tasks grow with project size, a useful skill in real DevOps work.
"What if we changed the archive pattern to include subfolders with many files? How would the time complexity change?"