Copying artifacts between jobs in Jenkins - Time & Space Complexity
When copying artifacts between Jenkins jobs, it's important to know how the time to copy grows as the number of artifacts increases.
We want to understand how the copying process scales with more files.
Analyze the time complexity of the following Jenkins pipeline snippet.
pipeline {
agent any
stages {
stage('Copy Artifacts') {
steps {
copyArtifacts(projectName: 'upstream-job', selector: lastSuccessful())
}
}
}
}
This code copies all artifacts from the last successful build of another job.
Look for repeated actions that affect time.
- Primary operation: Copying each artifact file one by one.
- How many times: Once for each artifact file in the source job.
As the number of artifact files grows, the copying time grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 file copy operations |
| 100 | 100 file copy operations |
| 1000 | 1000 file copy operations |
Pattern observation: The time grows directly with the number of files copied.
Time Complexity: O(n)
This means the copying time increases linearly as the number of artifact files increases.
[X] Wrong: "Copying artifacts happens instantly no matter how many files there are."
[OK] Correct: Each file must be copied individually, so more files mean more time.
Understanding how copying artifacts scales helps you design efficient pipelines and manage build times well.
What if we compressed all artifacts into one file before copying? How would the time complexity change?