Skip to content

Instantly share code, notes, and snippets.

@jb68
Created August 23, 2019 20:29
Show Gist options
  • Save jb68/d411db6190890edf4a774cd2d3fcd3dd to your computer and use it in GitHub Desktop.
Save jb68/d411db6190890edf4a774cd2d3fcd3dd to your computer and use it in GitHub Desktop.
Delete old builds in jenkins and last 5. This script needs to be exec in jenkins script console
def jobName = "aa"
def noOfJobsToKeep=5
def job = Jenkins.instance.getItem(jobName)
job.getBuilds().findAll { it.number < job.getBuilds().number.max() - noOfJobsToKeep }.each { it.delete() }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment