How To Clean and Reset Jenkins Build History

After building a Jenkins job, chances are you have left yourself with multiple builds as you have been testing with a large amount of those being failures.

 

Jenkins-failed-builds

If you want to clean this up before moving your job into production, you can run a simple script to do so.

 

1.Navigate to the Jenkins Script Console.

From the Jenkins home page > Manage Jenkins > Script Console

Jenkins-Script-Console

 

2.Paste the script below into the Script Console.

Don’t forget to replace “job_folder with the location of your job. Include the quotes and any subfolder that your job resides in.

def jobName = "job_folder"
def job = Jenkins.instance.getItem(jobName)
job.getBuilds().each { it.delete() }
job.nextBuildNumber = 1
job.save()

 

Example:

def jobName = "JOB_ROOT/JOB_SUB/JOB"
def job = Jenkins.instance.getItem(jobName)
job.getBuilds().each { it.delete() }
job.nextBuildNumber = 1
job.save()

 

 

Your build history should now be clean.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.