当前位置:网站首页>Jenkins batch delete build history

Jenkins batch delete build history

2020-12-08 08:05:26 Airship

(1) stay Manage Jenkins -> Script Console【 Execute script deletion 】:

Method 1 【 Delete an interval 】:

import jenkins.model.*;
import hudson.model.Fingerprint.RangeSet;

// The name of the job【 Directory name , If not, you can leave it blank 】.
def jobName = " Directory name / Project name ";
// The range of build numbers to delete.
def buildRange = "1214-1221";
def j = jenkins.model.Jenkins.instance.getItemByFullName(jobName);
def r = RangeSet.fromString(buildRange, true);
j.getBuilds(r).each { it.delete() }

Method 2 【 Delete no more than maxNumber The record of 】:

def jobName = " Directory name / Project name "
def maxNumber = 1213
Jenkins.instance.getItemByFullName(jobName);
Jenkins.instance.getItemByFullName(jobName).builds.findAll {
  it.number <= maxNumber
}.each {
  it.delete()
}

(2) Automatically discard build history data

 Project directory page —> Enter the project where you want to automatically clear the construction history —>Configure( To configure )—>General( Universal )
—>Discard old builds( Discard old builds )—>Max # of builds to keep( Keep the maximum number of builds )—> modify save that will do . 

A build contains two products : Build records and build artifacts . Building records is a kind of tracking 、 The basis for analysis and feedback , It has preservation value ; An obsolete build artifact can usually be discarded directly . Based on the above ideas ,Jenkins For us “ Discard old builds ” Configuration functions , Through reasonable configuration, the effect of saving construction records and discarding construction artifacts can be achieved , The configuration is as follows :

Here we need to fill in the custom discard old build settings , Here we will “ Days to keep building ” as well as “ Release package retention days ” All set to 7 God , take “ Keep the maximum number of builds ” Set to 30 strip , And we take it every time jar Package or war When you package, you just want to get the latest version , So we only store the latest version of the software version information , So in the “ Release package maximum retention # Construction ” Fill in 1, After filling in , Click on 【 preservation 】 Button to make the new settings take effect .

reference :

  1. Jenkins How to delete construction history in batches , Batch deletion build history
  2. jenkins Delete Build History Building history
  3. https://github.com/jenkinsci/jenkins-scripts/blob/master/scriptler/bulkDeleteBuilds.groovy
  4. Jenkins Server disk space full problem solved

 

版权声明
本文为[Airship]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/202012080656380051.html