詹金斯(Jenkins)删除所有作业的最新版本比最新的20个版本更旧的版本 [英] Jenkins delete builds older than latest 20 builds for all jobs
问题描述
我正在清理Jenkins(它的设置不正确),并且我需要删除每个工作早于最新的20个版本的版本.
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 any way to automate this using a script or something?
我找到了许多解决方案来删除特定作业的某些内部版本,但似乎无法一次为所有作业找到任何内容.
I found many solutions to delete certain builds for specific jobs, but I can't seem to find anything for all jobs at once.
非常感谢您的帮助.
推荐答案
You can use the Jenkins Script Console to iterate through all jobs, get a list of the N most recent and perform some action on the others.
import jenkins.model.Jenkins
import hudson.model.Job
MAX_BUILDS = 20
for (job in Jenkins.instance.items) {
println job.name
def recent = job.builds.limit(MAX_BUILDS)
for (build in job.builds) {
if (!recent.contains(build)) {
println "Preparing to delete: " + build
// build.delete()
}
}
}
Jenkins脚本控制台是用于此类管理维护的出色工具,并且通常存在一个现有脚本,其功能类似于您想要的.
The Jenkins Script Console is a great tool for administrative maintenance like this and there's often an existing script that does something similar to what you want.
这篇关于詹金斯(Jenkins)删除所有作业的最新版本比最新的20个版本更旧的版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!