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,280 points

edited Aug 9, 2018 by Kalgi 1,759 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:

answered May 7 by Atul

selected May 7 by Kalgi
+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")
item.builds.each() { build ->
answered Aug 2, 2018 by Sophie may
• 9,410 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 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 by Venkat

Related Questions In Jenkins

0 votes
1 answer

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

Yes this is possible. Follow these steps. 1. ...READ MORE

answered Jun 20 in Jenkins by Arvind
• 1,410 points
+1 vote
1 answer

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 in Jenkins by Sirajul
• 5,160 points

edited May 28 by Sirajul 53 views
0 votes
1 answer
0 votes
1 answer
+13 votes
2 answers
0 votes
1 answer
+1 vote
3 answers