0
0
Jenkinsdevops~10 mins

Milestone step for concurrency in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Milestone step for concurrency
Start Pipeline
Run Stage 1
Reach Milestone
Check for Previous Milestone
Wait
Run Stage 2
End Pipeline
The pipeline runs stages until it reaches a milestone. If a previous build reached the same milestone, the current build waits or skips to avoid concurrency conflicts.
Execution Sample
Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        milestone 1
      }
    }
  }
}
This Jenkins pipeline uses a milestone step to prevent concurrent builds from passing the same point simultaneously.
Process Table
StepBuild NumberMilestone ReachedPrevious Build MilestoneActionPipeline State
1Build #1Milestone 1NoneProceedBuild #1 at Milestone 1
2Build #2Milestone 1Build #1 reached Milestone 1Wait or SkipBuild #2 waiting at Milestone 1
3Build #1Passed Milestone 1N/AContinueBuild #1 proceeds past Milestone 1
4Build #2Milestone 1Build #1 passed Milestone 1ProceedBuild #2 proceeds past Milestone 1
5Build #2EndN/ACompleteBuild #2 finished
💡 Build #2 waits at Milestone 1 until Build #1 passes it, then proceeds and finishes.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
Build #1 StateNot startedAt Milestone 1Passed Milestone 1Passed Milestone 1CompletedCompleted
Build #2 StateNot startedWaiting at Milestone 1Waiting at Milestone 1At Milestone 1ProceededCompleted
Key Moments - 2 Insights
Why does Build #2 wait at the milestone instead of proceeding immediately?
Because Build #1 has already reached the same milestone and not passed it yet, Build #2 must wait to avoid concurrency conflicts, as shown in execution_table row 2.
What happens when Build #1 passes the milestone?
Once Build #1 passes the milestone (row 3), Build #2 is allowed to proceed past the milestone (row 4), ensuring only one build passes at a time.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the state of Build #2 at Step 2?
ABuild #2 is proceeding past Milestone 1
BBuild #2 has finished
CBuild #2 is waiting at Milestone 1
DBuild #2 has not started
💡 Hint
Check the 'Action' and 'Pipeline State' columns at Step 2 in the execution_table.
At which step does Build #2 proceed past Milestone 1?
AStep 4
BStep 2
CStep 1
DStep 5
💡 Hint
Look for when Build #1 has passed the milestone and Build #2 moves forward in the execution_table.
If Build #1 never passed Milestone 1, what would happen to Build #2?
ABuild #2 would proceed immediately
BBuild #2 would wait indefinitely at Milestone 1
CBuild #2 would skip the milestone
DBuild #2 would fail
💡 Hint
Refer to the waiting behavior shown in execution_table rows 2 and 3.
Concept Snapshot
milestone <number> step in Jenkins pipeline
- Prevents concurrent builds passing the same point
- Later builds wait if earlier builds haven't passed milestone
- Ensures orderly pipeline execution
- Use milestone to avoid race conditions in concurrency
Full Transcript
This visual execution trace shows how the Jenkins milestone step controls concurrency in pipelines. The pipeline starts with Build #1 reaching milestone 1 and proceeding. When Build #2 reaches the same milestone, it detects Build #1 has not passed it yet and waits. After Build #1 passes milestone 1, Build #2 proceeds and finishes. Variables track each build's state at each step. Key moments clarify why builds wait and when they proceed. The quiz tests understanding of build states and milestone behavior. The snapshot summarizes the milestone step's purpose and usage.