0
0
Jenkinsdevops~20 mins

Milestone step for concurrency in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Milestone Step for Concurrency Control in Jenkins Pipelines
📖 Scenario: You are managing a Jenkins pipeline that deploys applications. Sometimes multiple builds run at the same time, but you want to make sure only the latest build proceeds past a certain point to avoid conflicts.
🎯 Goal: Build a Jenkins pipeline script that uses the milestone step to control concurrency, allowing only the newest build to continue past the milestone.
📋 What You'll Learn
Create a Jenkins pipeline script with a milestone step
Add a stage before the milestone to simulate build preparation
Add a stage after the milestone to simulate deployment
Use the milestone step with an explicit ordinal number
Print messages to show the pipeline progress
💡 Why This Matters
🌍 Real World
In real Jenkins pipelines, the milestone step helps prevent multiple builds from deploying at the same time, avoiding conflicts and wasted resources.
💼 Career
Understanding concurrency control in Jenkins pipelines is important for DevOps engineers to maintain stable and efficient CI/CD workflows.
Progress0 / 4 steps
1
Create the initial Jenkins pipeline with a preparation stage
Write a Jenkins pipeline script that defines a pipeline block with an agent any and a stage named 'Preparation'. Inside this stage, add a steps block that prints 'Starting build preparation'.
Jenkins
Need a hint?

Use echo inside steps to print the message.

2
Add a milestone step with ordinal 1 after preparation
Add a new stage named 'Milestone' after the 'Preparation' stage. Inside its steps block, add a milestone 1 step to mark the concurrency control point.
Jenkins
Need a hint?

The milestone step takes an integer ordinal to identify the milestone.

3
Add a deployment stage after the milestone
Add a stage named 'Deploy' after the 'Milestone' stage. Inside its steps block, add an echo statement that prints 'Deploying application'.
Jenkins
Need a hint?

Use echo to print the deployment message inside the Deploy stage.

4
Print a final message after deployment
Add a post block to the pipeline with a always condition. Inside it, add a script block that prints 'Pipeline finished' using echo.
Jenkins
Need a hint?

The post block runs after all stages. Use always to run regardless of success or failure.