Post-build actions in Jenkins - Time & Space Complexity
We want to understand how the time taken by post-build actions changes as the number of actions grows.
How does adding more post-build steps affect the total execution time?
Analyze the time complexity of the following Jenkins post-build actions snippet.
post {
success {
echo 'Build succeeded'
archiveArtifacts artifacts: '**/target/*.jar'
}
failure {
mail to: 'team@example.com', subject: 'Build Failed', body: 'Please check the logs.'
}
}
This snippet runs different actions after the build depending on success or failure.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Executing each post-build action once per build result.
- How many times: Each action runs exactly once per build, no loops or recursion.
Execution time grows linearly as more post-build actions are added.
| Input Size (number of post-build actions) | Approx. Operations |
|---|---|
| 1 | 1 action executed |
| 5 | 5 actions executed |
| 10 | 10 actions executed |
Pattern observation: Doubling the number of post-build actions roughly doubles the total execution time.
Time Complexity: O(n)
This means the total time grows directly in proportion to the number of post-build actions.
[X] Wrong: "Post-build actions run all at once, so adding more doesn't affect time much."
[OK] Correct: Each action runs one after another, so more actions add more time overall.
Understanding how post-build actions scale helps you design efficient Jenkins pipelines that run smoothly as they grow.
What if post-build actions were run in parallel? How would the time complexity change?