How to restart from a checkpoint and mutate a build parameter in Pipeline?

Article ID:207126738
1 minute readKnowledge base

Issue

It would be nice to restart from a checkpoint, and mutate a build parameter. The use case here is someone clicks "run from this checkpoint" and unchecks the platforms (on by default) they do not wish to rerun.

Environment

  • CloudBees Jenkins Platform

  • Pipeline Plugin

Resolution

This can be accomplished by storing the original build number before creating a checkpoint, and then comparing the stored build number against the current build number whenever you want to know if the build has resumed:

def origBuildNumber = BUILD_NUMBER
checkpoint 'about to run'
def platforms
if (origBuildNumber == BUILD_NUMBER) {
  platforms = 'amd64,linux,solaris,NT'
} else {
  // resumed build
  def selections = input …
  platforms = …using selections…
}
node {
  sh "make clean all -plats=${platforms}"
}