Skip to content
Latchkey

How to Abort Older Builds With the milestone Step in Jenkins

The milestone step aborts any earlier build that has not yet passed the same milestone when a newer build reaches it.

Place a milestone step early in the pipeline. When a newer build passes that milestone, Jenkins aborts older builds still behind it. Pair with disableConcurrentBuilds for stricter serialization.

Steps

  • Add a milestone() step at the start of the pipeline.
  • A newer build passing the milestone aborts older builds behind it.
  • Add options { disableConcurrentBuilds() } to fully serialize a branch.

Jenkinsfile

Jenkinsfile
pipeline {
  agent any
  options { disableConcurrentBuilds() }
  stages {
    stage('Guard') {
      steps { milestone(ordinal: 1) }
    }
    stage('Build') {
      steps { sh 'make build' }
    }
  }
}

Gotchas

  • milestone only aborts builds that started earlier and have not yet reached it.
  • For deploy stages you usually want serialization, not aborting work mid-release.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →