Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Due to a misconfiguration, I have over 1700 failed builds in a Jenkins job.

How can I efficiently clean them?

share|improve this question
add comment

1 Answer

up vote 12 down vote accepted

You have several options:

  • Temporarily set the number of builds to keep in the job configuration (Discard Old Builds) so that those builds will be deleted when the next build finishes. If the next build is 1800, set it to keep the most recent 85 or so. Mark all older builds (i.e. 1 to 10) as Keep This Build Forever before starting the next build. This option will fail to delete some builds if you have a downstream job that prevents upstream builds from being deleted (not a problem in your situation if all of them failed though).

  • Use the Script Console in Manage Jenkins. If it's a top level job (not in a folder), the following will do the trick:

    Jenkins.instance.getItemByFullName('JobName').builds.findAll { it.number > 10 && it.number < 1717 }.each { it.delete() }

    Of course, this approach generally requires good backups. There's a lot you can break using the script console.

  • Delete the builds' folders from disk (by default in $JENKINS_HOME/jobs/JobName/builds/, using the start time stamp as folder name) and restart Jenkins, or Reload Configuration From Disk. This option will not allow plugins that e.g. keep the SVN history in order by moving any changes to the subsequent build to do their job.

share|improve this answer
2  
I've found another solution: Using jenkins-cli.jar -s ... delete-builds envjs 11-1717 –  Aaron Digulla Apr 30 '13 at 9:04
    
Made a Gist to list all the jobs with a build count via the terminal. Makes it easier to find jobs that need cleaning up. Could be used via cron as an email report too. –  Nick Feb 3 at 12:17
    
@Nick Check out the Groovy plugin, specifically the system Groovy build step type. No need to go outside Jenkins for this, just create a job that does this. jenkins.model.Jenkins.instance.getAllItems(hudson.model.Job.class).each { println it.fullDisplayName + " has " + it.builds.size() + " builds" } ; return Sorting e.g. by builds is similarly trivial. –  Daniel Beck Feb 3 at 17:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.