Quick Groovy script to delete Job builds

Barak Korren bkorren at redhat.com
Thu Mar 17 12:38:37 UTC 2016


Hi there,


Working on cleaning up Jenkins I came up with the following Groovy script:

  job_name = 'ovirt-engine_3.6_build-artifacts-fc22-x86_64'
  successful_to_keep = 5

  job = Hudson.instance.getJob(job_name)

  recent_success_times =
    job._getRuns().
    findAll({k, v -> v.result == Result.SUCCESS }).
    collect([], { k, v -> v.time }).
    sort().reverse().take(successful_to_keep)

  third_success = recent_success_times.last()

  job._getRuns().
    findAll({ k, v -> v.time < third_success }).
    each({ k, v -> v.delete() })

The script deletes all builds older then the 5th last successful build.

-- 
Barak Korren
bkorren at redhat.com
RHEV-CI Team



More information about the Infra mailing list