0
0
Jenkinsdevops~5 mins

Milestone step for concurrency in Jenkins - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Milestone step for concurrency
O(1)
Understanding Time Complexity

When using the milestone step in Jenkins pipelines, it helps control how concurrent builds proceed.

We want to understand how the time to process builds changes as more builds run at once.

Scenario Under Consideration

Analyze the time complexity of the following Jenkins pipeline snippet using milestone.

pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        milestone 1
        echo 'Building...'
      }
    }
    stage('Test') {
      steps {
        milestone 2
        echo 'Testing...'
      }
    }
  }
}
    

This pipeline uses milestone steps to ensure only the latest build passes each milestone, cancelling older ones.

Identify Repeating Operations

Look for repeated or concurrent operations that affect execution time.

  • Primary operation: Multiple builds running concurrently, each hitting milestone steps.
  • How many times: Number of concurrent builds trying to pass milestones.
How Execution Grows With Input

As more builds run at the same time, the milestone step cancels older builds to keep only the latest.

Concurrent Builds (n)Approx. Active Builds After Milestone
101 (latest build continues)
1001 (only newest build proceeds)
10001 (milestone cancels all but latest)

Pattern observation: Regardless of how many builds start, only one build passes each milestone, so execution time stays stable.

Final Time Complexity

Time Complexity: O(1)

This means the time to pass a milestone does not grow with more concurrent builds because older builds are cancelled.

Common Mistake

[X] Wrong: "More concurrent builds mean longer wait times at milestones because all builds wait their turn."

[OK] Correct: The milestone step cancels older builds, so only the newest build continues, keeping wait time constant.

Interview Connect

Understanding how concurrency controls like milestone affect build time helps you design efficient pipelines and explain your reasoning clearly.

Self-Check

"What if we removed the milestone steps? How would the time complexity change with many concurrent builds?"