Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jarek-przygodzki/cc8a2f765d9cbee30f7a to your computer and use it in GitHub Desktop.
Save jarek-przygodzki/cc8a2f765d9cbee30f7a to your computer and use it in GitHub Desktop.
Delete Jenkins build history
// change this variable to match the name of the job whose builds you want to delete
def jobName = "Your Job Name"
def job = Jenkins.instance.getItem(jobName)
job.getBuilds().each { it.delete() }
// reset the build number to 1
job.nextBuildNumber = 1
job.save()
@zikezhang
Copy link

def myjobs= [
'task_1':36,
'task_2':7,
'task_3':7,
'task_4':7
]

for (myjob in myjobs) {
Jenkins.instance.getItemByFullName(myjob.key).builds.findAll {
it.number <= myjob .value
}.each {
it.delete()
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment