0
0
Jenkinsdevops~5 mins

Post section (success, failure, always) in Jenkins - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Post section (success, failure, always)
O(1)
Understanding Time Complexity

We want to understand how the time taken by a Jenkins pipeline changes when using the post section with success, failure, and always blocks.

Specifically, how does adding these blocks affect the overall execution time as the pipeline grows?

Scenario Under Consideration

Analyze the time complexity of the following Jenkins pipeline snippet.

pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
  }
  post {
    success {
      echo 'Success!'
    }
    failure {
      echo 'Failure!'
    }
    always {
      echo 'Always runs'
    }
  }
}

This pipeline runs a build stage and then runs different post blocks depending on the build result.

Identify Repeating Operations

Look for repeated actions or loops in the post section.

  • Primary operation: The post section runs exactly one of the success or failure blocks, plus the always block.
  • How many times: Each post block runs once per pipeline execution, no loops or recursion.
How Execution Grows With Input

The post section runs a fixed number of steps regardless of pipeline size.

Input Size (n)Approx. Operations
103 (success/failure + always)
1003
10003

Pattern observation: The number of post steps does not grow with input size; it stays constant.

Final Time Complexity

Time Complexity: O(1)

This means the post section runs a fixed number of steps no matter how big the pipeline or input is.

Common Mistake

[X] Wrong: "The post section runs multiple times and grows with the number of stages or steps."

[OK] Correct: The post section runs only once after the entire pipeline finishes, so its execution time does not increase with pipeline size.

Interview Connect

Understanding fixed versus growing execution parts in pipelines helps you design efficient CI/CD workflows and explain your reasoning clearly in interviews.

Self-Check

"What if the post section contained loops or calls to other jobs? How would that affect the time complexity?"