Wednesday, May 04, 2016

How to clean and reset Jenkins build history

When you working with Jenkins while building your solution, definitely you have to run your project multiple times. It will result to a long Build History list that looks ugly and unnecessary for your production environment.

 If you need to clean this Build History, and reset the build number, you can run a simple script in  Jenkins Script Console. Here are the steps to do so.

1. Go to `Jenkins Script Console`
Go to your Jenkins home page > Manage Jenkins > Script Console

2. Run the script to clean and reset

Copy and paste this script to your Console Script text area and change the "copy_folder" to project name that you need to clean the history. Then click the "Run button".

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

Now check your Build History for the particular project, Wow!, it's clean now!


  1. Awesome...worked like a charm!

  2. Script deletes build history for me. But build # reset to 1 not working. Could you please help?

  3. Doesn't work for multibranch pipeline projects. Any advise?

  4. Very Nice it works
    THX !!! ;)

  5. The build starts from previous build number even if its cleared any help on this ? The change is momentary

  6. Nice blog..! I really loved reading through this article. Thanks for sharing such a amazing post with us and keep blogging... best angularjs training institute in chennai | angularjs training in omr | angular 4 training in chennai | angularjs training in chennai

  7. Thank you for the nice article here. Really nice and keep update to explore more gaming tips and ideas.

    Focus Group Testing

    PC Game Testing

    Mobile Game Testing

    Console Game Testing