1.删除所有的Jenkins中的Job的编译历史并重置build号
import hudson.model.*
def items = Hudson.instance.allItems
items.each { item ->
if (item instanceof Job) {
def builds = item.getBuilds()
builds.each { build ->
def since = groovy.time.TimeCategory.minus( new Date(), build.getTime() )
def status = build.getBuildStatusSummary().message
println "Build: ${build} | Since: ${since} | Status: ${status}"
build.delete()
}
item.nextBuildNumber = 1
item.save()
}
}
return
2.删除某个Job的Jenkins中编译历史并重置build号
import hudson.model.*
def item = jenkins.model.Jenkins.instance.getItem("Job名字");
def builds = item.getBuilds()
builds.each { build ->
def since = groovy.time.TimeCategory.minus( new Date(), build.getTime() )
def status = build.getBuildStatusSummary().message
println "Build: ${build} | Since: ${since} | Status: ${status}"
build.delete()
}
item.nextBuildNumber = 1
item.save()
return
3.将所有的Jenkins的Job的保留的编译build历史数量(保证Jenkins所在机器的健康性)
import hudson.model.*
def items = Hudson.instance.allItems
items.each { item ->
if (item instanceof Job) {
item.logRotator = new hudson.tasks.LogRotator ( "", "10", "", "")
println "$item.name fixed "
}
}
return