Controlling jenkins pipelines

3 steps can be used to control a jenkins pipeline

Stage
Lock
Milestone

stage the stage step remains but is now focused on grouping steps and providing boundaries for Pipeline segments.

example

stage('Build') {
steps{
script{
startbuild()
sh "echo $PATH"
}
}
}
}

This creates a simple visualize view in "stage view" of your pipeline plugin called build. which executes the startbuild() function

Lock this step limits concurency to a single build

stage('Build') {
steps{
script{
startbuild()
lock('lockedresource'){
sh "echo $PATH"
}
}
}
}
}

Lock can be used for restricting steps in a stage or for wrapping multiple stages to a single run path.

milestone ensures that older builds of a job do not overwrite a newer build

example

Build 1 is triggered

Build 2 is triggered

Build 2 builds faster than Build 1 and enters the Test stage sooner.

Rather than allowing Build 1 to continue and possibly overwrite the newer artifact produced in Build 2, you can use the milestone step to abort Build 1:

stage('Build') {
milestone()
echo "Building"
}
stage('Test') {
milestone()
echo "Testing"
}