Quick Groovy script to delete Job builds

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@redhat.com RHEV-CI Team

--Md/poaVZ8hnGTzuv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 03/17 14:38, Barak Korren wrote:
Hi there, =20 =20 Working on cleaning up Jenkins I came up with the following Groovy script: =20 job_name =3D 'ovirt-engine_3.6_build-artifacts-fc22-x86_64' successful_to_keep =3D 5 =20 job =3D Hudson.instance.getJob(job_name) =20 recent_success_times =3D job._getRuns(). findAll({k, v -> v.result =3D=3D Result.SUCCESS }). collect([], { k, v -> v.time }). sort().reverse().take(successful_to_keep) =20 third_success =3D recent_success_times.last() =20 job._getRuns(). findAll({ k, v -> v.time < third_success }). each({ k, v -> v.delete() }) =20 The script deletes all builds older then the 5th last successful build.
There's a plugin installed called 'scriptler' that allows you to put those groovy scripts there, there are already a couple iirc
=20 --=20 Barak Korren bkorren@redhat.com RHEV-CI Team _______________________________________________ Infra mailing list Infra@ovirt.org http://lists.ovirt.org/mailman/listinfo/infra
--=20 David Caro Red Hat S.L. Continuous Integration Engineer - EMEA ENG Virtualization R&D Tel.: +420 532 294 605 Email: dcaro@redhat.com IRC: dcaro|dcaroest@{freenode|oftc|redhat} Web: www.redhat.com RHT Global #: 82-62605 --Md/poaVZ8hnGTzuv Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJW6qW9AAoJEEBxx+HSYmnDy7cH/0HWvrFaJI22+vch6YpOKYTd YLUkNUJKNMB9aTeM1pSRv+dMjGtlyaBDXunZmiy/g3iaSEnUzmirCvhO+EUFhCaU 9JgZVkpd8VngsSuL9/xkc6BG8X3Hhq7K/aJp+99szUYLPInu4Vo1AlCScxDemESy 9I5Phco8cqLMGQJuaQhWN0gtYT9YtZ/4C+MgSY9mUJzFA6u+jv7t1LYFAboEYbkj Ud9P/YRVMY+JFgdqD+A18RfYBlst2qv5gkJhpbISa4vaTl4qYGST4Waxea3rAMSd ZGQC7zFrT/RyHiDx5djkIyLacyJmLB3iXmwO3dQ399nBiuzdrggE6y/9FGdD2Ww= =/g2k -----END PGP SIGNATURE----- --Md/poaVZ8hnGTzuv--

Yea, its located here: http://jenkins.ovirt.org/scriptler/ I see you already added it :) I've sent a patch to specify this option, as it might contain useful commands: https://gerrit.ovirt.org/#/c/54955/ e. On Thu, Mar 17, 2016 at 12:40 PM, David Caro <dcaro@redhat.com> wrote:
Hi there,
Working on cleaning up Jenkins I came up with the following Groovy
On 03/17 14:38, Barak Korren wrote: 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.
There's a plugin installed called 'scriptler' that allows you to put those groovy scripts there, there are already a couple iirc
-- Barak Korren bkorren@redhat.com RHEV-CI Team _______________________________________________ Infra mailing list Infra@ovirt.org http://lists.ovirt.org/mailman/listinfo/infra
-- David Caro
Red Hat S.L. Continuous Integration Engineer - EMEA ENG Virtualization R&D
Tel.: +420 532 294 605 Email: dcaro@redhat.com IRC: dcaro|dcaroest@{freenode|oftc|redhat} Web: www.redhat.com RHT Global #: 82-62605
_______________________________________________ Infra mailing list Infra@ovirt.org http://lists.ovirt.org/mailman/listinfo/infra
-- Eyal Edri Associate Manager RHEV DevOps EMEA ENG Virtualization R&D Red Hat Israel phone: +972-9-7692018 irc: eedri (on #tlv #rhev-dev #rhev-integ)

On 19 March 2016 at 19:16, Eyal Edri <eedri@redhat.com> wrote:
Yea, its located here: http://jenkins.ovirt.org/scriptler/ I see you already added it :)
Yhead I did, but after I did I thought about it and reached the conclusion that this scriptler is nothing more then a crippled kind of job without execution history and that tries to block your borwser session while its running. Might as well just write free-style projects that run on master and have a system-groovy build step, then we can maintain them with JJB. -- Barak Korren bkorren@redhat.com RHEV-CI Team
participants (3)
-
Barak Korren
-
David Caro
-
Eyal Edri