How to reset build number in jenkins?

I am using Jenkins and Gradle to build my java project.

Every time I build my project, I get a new build number on the Jenkins screen.

The following is my Jenkins build info:

Success > Console Output  #96   03-Jan-2014 15:35:08    
Success > Console Output  #95   03-Jan-2014 15:27:29     
Failed > Console Output  #94    03-Jan-2014 15:26:16     
Failed > Console Output  #93    03-Jan-2014 15:25:01     
Failed > Console Output  #92    03-Jan-2014 15:23:50     
Success > Console Output  #91   03-Jan-2014 12:42:32    
Success > Console Output  #90   03-Jan-2014 12:02:45

I want to reset the Jenkins build number like:

Success > Console Output  #1    03-Jan-2014 12:02:45

How can I reset the build number in Jenkins?


Solution 1:

Can be easier done from groovy script console . Go to http://your-jenkins-server/script In script window enter:

item = Jenkins.instance.getItemByFullName("your-job-name-here")
//THIS WILL REMOVE ALL BUILD HISTORY
item.builds.each() { build ->
  build.delete()
}
item.updateNextBuildNumber(1)

Solution 2:

From here

Given your Hudson job is named FooBar,

  • rename FooBar to FooBar-Copy
  • create a new job named FooBar, using 'Copy existing job' option, from FooBar-Copy
  • delete FooBar-Copy

Solution 3:

  • First wipeout workspace and get rid of previous builds.
    • On the server navigate to the job dir eg. 'var/lib/jenkins/jobs/myJob' delete the workspace & build dirs as well as any polling files, lastSuccessful, lastStable files etc. You should only have config.xml and lastBuildNumber.
    • Shut down jenkins using something like service jenkins stop
    • Edit the file called nextBuildNumber, inserting 1 instead of the current build number
    • Start up jenkins again, service jenkins start
    • Log into jenkins and go to your job and hit build. Should start building job#1