Skip to content

Instantly share code, notes, and snippets.

@pwalkr
Created June 9, 2022 14:53
Show Gist options
  • Save pwalkr/304017515e7be403c3b418f39a19be0c to your computer and use it in GitHub Desktop.
Save pwalkr/304017515e7be403c3b418f39a19be0c to your computer and use it in GitHub Desktop.
Abort build on indexing trigger
import hudson.model.Result
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
// Callable as a step, defined in vars/
void call() {
if (this.isBranchIndexingCause()) {
echo "ABORTED: $message"
throw new FlowInterruptedException(Result.NOT_BUILT)
}
}
// Based on https://stackoverflow.com/a/56775578
@NonCPS
Boolean isBranchIndexingCause() {
return currentBuild.rawBuild.getCause(jenkins.branch.BranchIndexingCause) ? true : false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment