Is there a way to change the Jenkins build number while building a job

+1 vote

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
Aug 2, 2018 in Jenkins by Tyrion anex
• 8,700 points

edited Aug 9, 2018 by Kalgi 29,832 views

4 answers to this question.

+1 vote
Best answer

If you have access to the script console (Manage Jenkins -> Script Console), then you can do this following:

Jenkins.instance.getItemByFullName("YourJobName").updateNextBuildNumber(1)
answered May 7, 2019 by Atul

selected May 7, 2019 by Kalgi
This not working for me. On the script console i didnt find any result after the execution. I am running this on my multibranch job

Jenkins.instance.getItemByFullName("Repo/branch").updateNextBuildNumber(1)

You can use the Next Build Number Plugin if the above doesn't work. Using the plugin is very simple and direct. Replace 47 with 1 in your case.

+1 vote

First of all you’ll need access to the script console which is in (Manage Jenkins -> Script Console).

 Then just run this command:

item = Jenkins.instance.getItemByFullName("your-job-name-here")
//THIS WILL REMOVE ALL BUILD HISTORY
item.builds.each() { build ->
  build.delete()
}
item.updateNextBuildNumber(1)
answered Aug 2, 2018 by Sophie may
• 10,620 points
+1 vote

You can use the Next Build Number Plugin. It's not required, there are other ways of doing this as mentioned by @atul. This is just another method.

This is a simple plugin that changes the next build number Jenkins will use for a job.
This plugin is typically useful if you are using the build number as part of a version string, and:

  • You do a build outside of Jenkins and you want to skip that number for the next build to avoid duplicate version numbers or failures.
  • You created a new job to handle an existing process and want it to continue from where the old one left off.
answered May 7, 2019 by Danica
+1 vote

Under the job workspace folder:

C:\Program Files (x86)\Jenkins\jobs\job_name

You'll find a file named nextBuildNumber. Set the build number in the file and reload the configuration from the disk. This will force the next build to start with the configured build number.

answered May 7, 2019 by Venkat

Another way, without having to go to the machine itself neither do file changes manually (please avoid it),

open the /script console and execute something like below

Jenkins.instance.getItemByFullName("<Full project name>").updateNextBuildNumber(5)

Related Questions In Jenkins

+1 vote
3 answers

How to auto build a job in jenkins if there is any change in code on Github repository?

To automatically run build on code commit, follow ...READ MORE

answered Jul 31, 2019 in Jenkins by Sirajul
• 59,230 points
78,910 views
+3 votes
2 answers

Is there a way to restrict permissions to a user per individual job in jenkins?

Yes, you can configure user permissions per ...READ MORE

answered May 28, 2019 in Jenkins by Sirajul
• 59,230 points

edited May 28, 2019 by Sirajul 112,514 views
0 votes
1 answer
0 votes
1 answer
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,064 views
+2 votes
1 answer
0 votes
1 answer

Getting below error on Jenkins while creating a Maven Build Job

When you are using ssh to connect, ...READ MORE

answered Sep 3, 2019 in Jenkins by Hari
2,276 views
+1 vote
3 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP