0
0
Jenkinsdevops~5 mins

Steps within stages in Jenkins - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Steps within stages
O(n)
Understanding Time Complexity

We want to understand how the time to run a Jenkins pipeline changes when we add more steps inside stages.

How does adding steps affect the total work Jenkins does?

Scenario Under Consideration

Analyze the time complexity of the following Jenkins pipeline snippet.

pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Step 1'
        echo 'Step 2'
        echo 'Step 3'
      }
    }
  }
}

This pipeline has one stage with three steps that run one after another.

Identify Repeating Operations

Look for repeated actions inside the pipeline.

  • Primary operation: Each step inside the stage runs once in order.
  • How many times: The number of steps determines how many operations run.
How Execution Grows With Input

As you add more steps, the total work grows directly with the number of steps.

Input Size (n = steps)Approx. Operations
33 steps run
1010 steps run
100100 steps run

Pattern observation: Doubling the steps doubles the work; it grows in a straight line.

Final Time Complexity

Time Complexity: O(n)

This means the total time grows directly with the number of steps you add inside the stage.

Common Mistake

[X] Wrong: "Adding more steps inside a stage does not affect the total time much because they run fast."

[OK] Correct: Even if each step is fast, adding many steps adds up and increases total time linearly.

Interview Connect

Understanding how steps add up helps you explain pipeline performance clearly and shows you grasp how Jenkins runs tasks.

Self-Check

"What if the steps inside the stage ran in parallel instead of one after another? How would the time complexity change?"