Due to a misconfiguration, I have over 1700 failed builds in a Jenkins job.
How can I efficiently clean them?
Best Answer
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:
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.
Go into the build you want to delete, and click the Delete this build button in the upper right corner.
If you need to clean the Jenkins build history, and reset the build number back to 1, you can run a simple script in Jenkins Script Console. source
Go to Jenkins Script Console.
Go to your Jenkins home page -> Manage Jenkins -> Script Console.
Run this script to clean and reset.
Copy and paste this script to your Console Script text area and change the "copy_folder" to the project name that you need to clean the history. Then click the Run button.
Best Answer
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:
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.