Jenkins delete builds older than latest 20 builds for all jobs

前端 未结 6 566
悲哀的现实
悲哀的现实 2021-01-02 01:30

I am in the process of cleaning up Jenkins (it was setup incorrectly) and I need to delete builds that are older than the latest 20 builds for every job.

Is there an

6条回答
  •  借酒劲吻你
    2021-01-02 02:32

    For Multibranch Pipelines, I modified the script by Dave Bacher a bit. Use this to delete builds older than the latest 20 build of "master" branches:

    MAX_BUILDS = 20
    
    for (job in Jenkins.instance.items) {
      if(job instanceof jenkins.branch.MultiBranchProject) {
        job = job.getJob("master")
        def recent = job.builds.limit(MAX_BUILDS)
        for (build in job.builds) {
          if (!recent.contains(build)) {
            println "Preparing to delete: " + build
            // build.delete()
          }
        }
      }
    }
    

提交回复
热议问题