import jenkins.model.jenkins
import hudson.model.job
import jenkins.model.builddiscarderproperty
import hudson.tasks.logrotator
// 遍历所有的任务
jenkins.instance.allitems(job).each { job ->
if ( job.isbuildable() && job.supportslogrotator() && job.getproperty(builddiscarderproperty) == null) {
println " "${job.fulldisplayname}" 处理中"
job.addproperty(new builddiscarderproperty(new logrotator (2, 10, 2, 10)))
println "$job.name 已更新"
}
}
return;
/**
logrotator构造参数分别为:
daystokeep: if not -1, history is only kept up to this days.
numtokeep: if not -1, only this number of build logs are kept.
artifactdaystokeep: if not -1 nor null, artifacts are only kept up to this days.
artifactnumtokeep: if not -1 nor null, only this number of builds have their artifacts kept.
**/