From aecf82b5459b003f00724c22e13676d16bb42f72 Mon Sep 17 00:00:00 2001 From: Hari Sekhon Date: Sat, 26 Nov 2022 18:03:05 +0000 Subject: [PATCH] added jenkins_clear_build_history_all_jobs.groovy --- jenkins_clear_build_history_all_jobs.groovy | 40 +++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 jenkins_clear_build_history_all_jobs.groovy diff --git a/jenkins_clear_build_history_all_jobs.groovy b/jenkins_clear_build_history_all_jobs.groovy new file mode 100644 index 00000000..1298245b --- /dev/null +++ b/jenkins_clear_build_history_all_jobs.groovy @@ -0,0 +1,40 @@ +// +// Author: Hari Sekhon +// Date: 2021-04-08 19:16:17 +0100 (Thu, 08 Apr 2021) +// +// vim:ts=4:sts=4:sw=4:noet +// +// https://github.com/HariSekhon/DevOps-Bash-tools +// +// License: see accompanying Hari Sekhon LICENSE file +// +// If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish +// +// https://www.linkedin.com/in/HariSekhon +// + +// Paste this into $JENKINS_URL/script +// +// Jenkins -> Manage Jenkins -> Script Console + +// XXX: WARNING: you can run into all sorts of state problems with the Milestone plugin preventing your builds from running due to a remnant reference to a higher build number - this also happens on job restores which start from build #1 again +// +// [2022-08-02T16:14:46.501Z] Trying to pass milestone 0 +// [2022-08-02T16:14:46.501Z] Canceled since build #3814 already got here +// +// https://issues.jenkins.io/browse/JENKINS-38641 +// +// one fix is of course to do +// +// job.nextBuildNumber = 3815 +// +// but you'd either need to do that for only one specific job (see adjacent script jenkins_clear_build_history.groovy) or you'd need to set the build number to something higher than any of the jobs got to + +jenkins.model.Jenkins.instance.items.findAll().each { + println + def jobName = it.name + def job = Jenkins.instance.getItem(jobName) + job.getBuilds().each { it.delete() } + job.nextBuildNumber = 1 + job.save() +}