Skip to main content

Best Strategy for Disk Space Management: Clean Up Old Builds

Comments

2 comments

  • 邵彬 Please Update

    Manage Jenkins -> Script Console

    def jobName = "Some_Job_Name"
    def maxNumber = 64
    
    Jenkins.instance.getItemByFullName(jobName).builds.findAll {
      it.number <= maxNumber
    }.each {
      it.delete()
    }
    -2
  • Jaydeep Dave

    How about this:

    def daysToKeep = 30
    def numToKeep = 10
    def artifactDaysToKeep = -1
    def artifactNumToKeep = -1

    Jenkins.instance.getAllItems(AbstractItem.class).each {
    println("=====================")
    println("JOB: " + it.name)
    println("Job type: " + it.getClass())

    if (it instanceof org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) {
    try {
    orpStrategy = new com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy(true, daysToKeep, numToKeep)
    it.setOrphanedItemStrategy(orpStrategy)
    it.save()
    println("")
    }catch(Exception e) {}

    }

    if (it instanceof org.jenkinsci.plugins.workflow.job.WorkflowJob) {
    try {
    it.buildDiscarder = new hudson.tasks.LogRotator(daysToKeep,numToKeep, artifactDaysToKeep, artifactNumToKeep)
    it.save()
    println("")
    }catch(Exception e) {}

    }
    };
    2

Please sign in to leave a comment.

About CloudBees Support

Our Support Engineers are available to help with any questions or problems you may have with any of our products.