Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

How can I efficiently clean them?

share|improve this question
A number of ways to delete builds via command line are discussed here:… – ThomasW Jul 4 '14 at 6:27
up vote 40 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
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 '14 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 '14 at 17:59

As Aaron stated correctly you can also use the Jenkins CLI for this purpose:

java -jar jenkins-cli.jar -s delete-builds <JobName> 11-1717
share|improve this answer

Simply make an API call:

curl -X POST[11-1717]/doDelete

To get the APIToken: login to Jenkins > Configuration > Show API Token.

share|improve this answer
I thinks this is the best approach to the problem. it can be executed remotely a provides a broad range of actions via REST – alfredocambera Aug 14 '15 at 20:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .