How to reset build number in jenkins?

I use Jenkins and Gradle to create my java project.

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

The following is information about my Jenkins:

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, for example:

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

How can I reset the build number in Jenkins?

Thanks in advance.

+78
jenkins
Jan 03 '14 at 10:45
source share
9 answers

It may be easier to make a groovy script from the console. Go to http: // your-jenkins-server / script . In the script window, type:

 item = Jenkins.instance.getItemByFullName("your-job-name-here") //THIS WILL REMOVE ALL BUILD HISTORY item.builds.each() { build -> build.delete() } item.updateNextBuildNumber(1) 
+138
Nov 03 '15 at 9:18
source share

From here

Given that your Hudson assignment is called FooBar,

  • rename FooBar to FooBar-Copy
  • create a new task named FooBar using the option "Copy an existing task" from FooBar-Copy
  • remove foobar-copy
+61
Jan 03 '14 at 12:11
source share
  • First wipeout workspace and get rid of previous builds.
    • On the server, go to work, for example. 'var / lib / jenkins / jobs / myJob' delete the workspace and assembly dirs, as well as any survey files, lastSuccessful, lastStable files, etc. You should only have the config.xml file and lastBuildNumber.
    • Shut down using something like jenkins service shutdown
    • Edit the file named nextBuildNumber by inserting 1 instead of the current build number
    • Run jenkins again, jenkins start service
    • Log in to jenkins and go to your work and click Build. Must get started # 1
+33
Jan 03 '14 at 19:09
source share

If you want to set the next build number, there is a "NextBuildNumber" plugin for this. But this will not work in your case, because the build number you need, which is 1, is less than your current build number.

Here you must first erase all previous assemblies. You can do this by running this simple script. Go to → Jenkins Management → Script Console

 // change this variable to match the name of the job whose builds you want to delete def jobName = "Your Job Name" def job = Jenkins.instance.getItem(jobName) job.getBuilds().each { it.delete() } 

Now you can set the next build number to 1 and start the build. It will start at 1 . :) It is so simple.

Update. Jenkins now has a Purge Job History plugin to make this the easiest. Checkout page for more information - https://wiki.jenkins.io/display/JENKINS/Purge+Job+History+Plugin

+19
Apr 03 '14 at 6:03
source share

More generally, reset your build number to N (where N not necessarily 1):

  • Remove any existing assemblies where buildNumber >= N
  • Change Program Files (x86)/Jenkins/jobs/yourjob/nextBuildNumber . Set the number it contains, N
  • From Jenkins, select Manage Jenkins -> Reload Configuration from Disk .
+6
Oct 12 '16 at 15:26
source share

Extending the accepted answer, here's how to do it for all projects at the same time:

 Jenkins.instance.allItems.each() { item -> item.builds.each() { build -> build.delete() } item.updateNextBuildNumber(1) } 
+5
Jan 23 '17 at 10:09 on
source share

As a follow-up to @antweiss's excellent answer, we can go further ...

There is no need to delete the complete build history, if you do not want this, you can simply drop the time to the previous point:

 resetNumberTarget = 14 item = Jenkins.instance.getItemByFullName("Project Name [from project Dashboard]") //println(item) item.builds.each() { build -> //println(build) //println(build.number) if(build.number >= resetNumberTarget) { //println("About to Delete '" + build + "'") build.delete() } } item.updateNextBuildNumber(resetNumberTarget) 

If you need a dummy run to verify what it is going to do without executing it, just comment out build.delete() and item.updateNextBuildNumber(resetNumberTarget) and uncomment the various print commands.




Documentation: Information about these objects was difficult to find, but I determined the following:
+2
Mar 01 '18 at 16:04
source share

You can use the nexBuildNumber plugin or simply change the nexBuildNumber file to the build number of reset. The following are the steps that must be completed:

  • Go to .jenkins/Jobs/<YourJobName>/build/ , take a backup copy of this folder (if you need to use it in the future) and delete the build folder.

Note. After cleaning old builds, you lose the build history and are no longer available on the Jenkins dashboard.

  • Reload configuration (Jenkins → Jenkins Management).
  • Set the next version of the assembly to 1, either using the Next Build Number nextBuildNumber in, or by changing the nextBuildNumber file in your directory.
+1
Jul 29 '15 at 10:22
source share

To reset the build numbers of all jobs:

 Jenkins.instance.getAllItems(AbstractProject.class).each { item = Jenkins.instance.getItemByFullName(it.fullName) //THIS WILL REMOVE ALL BUILD HISTORY item.builds.each() { build -> build.delete() } item.updateNextBuildNumber(1) } 
-one
Mar 16 '18 at 5:35
source share



All Articles