Stash and unstash for passing data in Jenkins - Time & Space Complexity
We want to understand how the time to stash and unstash data changes as the amount of data grows.
How does Jenkins handle passing files between pipeline stages as data size increases?
Analyze the time complexity of the following Jenkins pipeline snippet.
stage('Build') {
steps {
sh 'make build'
stash name: 'app', includes: '**/target/**'
}
}
stage('Test') {
steps {
unstash 'app'
sh 'make test'
}
}
This code builds the app, saves the build files with stash, then retrieves them with unstash for testing.
Look for repeated actions that affect time.
- Primary operation: Stashing and unstashing files involves copying files to and from the Jenkins master.
- How many times: Each stash and unstash runs once per pipeline execution, but the time depends on the number and size of files.
As the number or size of files grows, the time to stash and unstash grows roughly in proportion.
| Input Size (files or total size) | Approx. Operations (file copy time) |
|---|---|
| 10 small files | Low time, quick copy |
| 100 files or larger size | About 10 times longer |
| 1000 files or very large size | Much longer, roughly 100 times more work |
Pattern observation: Time grows roughly linearly with the amount of data being stashed or unstashed.
Time Complexity: O(n)
This means the time to stash and unstash grows directly with the number and size of files involved.
[X] Wrong: "Stash and unstash time stays the same no matter how many files we pass."
[OK] Correct: More files or bigger files take more time to copy, so time grows with data size.
Understanding how data passing scales helps you design efficient pipelines and explain trade-offs clearly.
"What if we compressed files before stashing? How would that affect the time complexity?"