0
0
Jenkinsdevops~5 mins

Build steps execution in Jenkins - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Build steps execution
O(n)
Understanding Time Complexity

We want to understand how the time to run build steps changes as we add more steps.

How does the total work grow when the number of build steps increases?

Scenario Under Consideration

Analyze the time complexity of the following Jenkins pipeline snippet.

pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        script {
          for (int i = 0; i < stepsList.size(); i++) {
            stepsList[i].execute()
          }
        }
      }
    }
  }
}

This code runs each build step one after another from a list of steps.

Identify Repeating Operations

Look for loops or repeated actions.

  • Primary operation: Loop over all build steps to execute each one.
  • How many times: Once for each build step in the list.
How Execution Grows With Input

As the number of build steps grows, the total time grows too.

Input Size (n)Approx. Operations
1010 executions
100100 executions
10001000 executions

Pattern observation: The total work grows directly with the number of steps.

Final Time Complexity

Time Complexity: O(n)

This means the time to finish all build steps grows in a straight line as you add more steps.

Common Mistake

[X] Wrong: "Running more build steps won't affect total time much because they run fast."

[OK] Correct: Even if each step is fast, doing many steps adds up and total time grows with the number of steps.

Interview Connect

Understanding how build steps add up helps you explain pipeline performance clearly and shows you can reason about process scaling.

Self-Check

"What if the build steps could run in parallel? How would the time complexity change?"