What is the main purpose of using the milestone step in a Jenkins pipeline?
Think about how Jenkins manages concurrent builds and avoids outdated work continuing.
The milestone step helps Jenkins pipelines handle concurrency by ensuring that if a newer build reaches a milestone, older builds that haven't reached it yet will be stopped. This prevents outdated builds from wasting resources.
Given the following Jenkins pipeline snippet, what will be the output if build #2 reaches the milestone before build #1?
pipeline {
agent any
stages {
stage('Build') {
steps {
milestone 1
echo "Build stage running"
}
}
stage('Test') {
steps {
milestone 2
echo "Test stage running"
}
}
}
}Remember that milestone stops older builds from passing milestones reached by newer builds.
When Build #2 reaches milestone 2 first, Build #1 is considered older and will be stopped before running the 'Test' stage, so it won't print 'Test stage running'. Build #2 runs fully.
In a Jenkins pipeline with parallel branches, how can the milestone step be used to ensure that only the latest build's parallel branches proceed beyond a certain point?
Think about how to stop outdated work in each parallel path individually.
By placing a milestone step at the start of each parallel branch, Jenkins can stop older builds from continuing in any branch once a newer build has passed that milestone, preventing wasted work in parallel branches.
A Jenkins pipeline with milestones unexpectedly stops an older build early. What is the most likely cause?
Consider how milestones affect concurrency and build ordering.
The milestone step aborts older builds that have not reached the milestone if a newer build has already passed it. This is the expected behavior to avoid running outdated builds.
What is the best practice when placing milestone steps in a complex Jenkins pipeline to manage concurrency effectively?
Think about saving time and resources by stopping outdated builds early.
Placing milestone steps before expensive or long stages helps stop older builds early, saving resources and reducing queue times, which is a best practice in complex pipelines.