0
0
Jenkinsdevops~5 mins

Post-build actions in Jenkins - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Post-build actions
O(n)
Understanding Time 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?

Scenario Under Consideration

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 Repeating Operations

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.
How Execution Grows With Input

Execution time grows linearly as more post-build actions are added.

Input Size (number of post-build actions)Approx. Operations
11 action executed
55 actions executed
1010 actions executed

Pattern observation: Doubling the number of post-build actions roughly doubles the total execution time.

Final Time Complexity

Time Complexity: O(n)

This means the total time grows directly in proportion to the number of post-build actions.

Common Mistake

[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.

Interview Connect

Understanding how post-build actions scale helps you design efficient Jenkins pipelines that run smoothly as they grow.

Self-Check

What if post-build actions were run in parallel? How would the time complexity change?