清理构建历史

1、删除 历史构建


//项目名称
def jobName = "you-job-name"
//删除小于等于64的构建历史
def maxNumber = 40
Jenkins.instance.getItemByFullName(jobName).builds.findAll {
  it.number <= maxNumber
}.each {
  it.delete()
}

2、清空所有构建

//项目名称
def jobName = "geostar-xuncha-portal-fat"
def item = Jenkins.instance.getItemByFullName(jobName);
item.builds.each {
  it.delete()
}
// 更新构建Number
item.updateNextBuildNumber(1)