Skip to content

Instantly share code, notes, and snippets.

@stroparo
Last active July 17, 2018 17:46
Show Gist options
  • Save stroparo/955ece95a2421ce2f9f1e3631b03e437 to your computer and use it in GitHub Desktop.
Save stroparo/955ece95a2421ce2f9f1e3631b03e437 to your computer and use it in GitHub Desktop.
Jenkins script snippets
// A collection of Jenkins scripts commonly used in the script console
// Jenkins script console is at YOUR_JENKINS_URL/script
// Build abortion
Jenkins.instance.getItemByFullName("entire/path/to/job[/branch]").getBuildByNumber(buildNum).finish(hudson.model.Result.ABORTED, new java.io.IOException("Aborting build"));
// Build deletion
Jenkins.instance.getItemByFullName("entire/path/to/job[/branch]").getBuildByNumber(buildNum).delete()
// Job listing
// https://support.cloudbees.com/hc/en-us/articles/226941767-Groovy-to-list-all-jobs
Jenkins.instance.getAllItems(AbstractItem.class).each {i -> println(i.fullName)};
Jenkins.instance.getAllItems(AbstractProject.class).each {i -> println(i.fullName)};
Jenkins.instance.getAllItems(jenkins.model.ParameterizedJobMixIn.ParameterizedJob.class).each { it -> println it.fullName }
Jenkins.instance.getAllItems(jenkins.model.ParameterizedJobMixIn.ParameterizedJob.class).each { it ->
if(it.isDisabled()) { println it.fullName }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment