Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Jenkins build number

Tags:

jenkins

People also ask

Can we reset Jenkins build number?

You can use either nexBuildNumber plug-in or simply modify nexBuildNumber file to reset build number. Following are the steps that you need to perform: Go to . jenkins/Jobs/<YourJobName>/build/ , take backup of this folder(if you need for future use) and delete build folder.

What is Jenkins build number?

BUILD_NUMBER is the current build number. You can use it in the command you execute for the job, or just use it in the script your job executes. See the Jenkins documentation for the full list of available environment variables.

How do I get previous build number in Jenkins?

Navigate to the Jenkins dashboard and select Build History. This timeline displays your build history. This table displays a list of your past builds, time since build and the status of each build.


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

Jenkins.instance.getItemByFullName("YourJobName").updateNextBuildNumber(45)

can be done with the plugin: https://wiki.jenkins-ci.org/display/JENKINS/Next+Build+Number+Plugin

more info: http://www.alexlea.me/2010/10/howto-set-hudson-next-build-number.html

if you don't like the plugin:

If you want to change build number via nextBuildNumber file you should "Reload Configuration from Disk" from "Manage Jenkins" page.


Under the job workspace folder, like:

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

there is a file named nextBuildNumber.

Setting the build number in the file and reloading the configuration from disk (Manage Jenkins menu) will force the next build you start to have the value from the file as BUILD_NUMBER.


If you have branch name including Forward Slash (using git flow for example), you will need to replace the Forward Slash with its Unicode character %2F within the branch name.

Here is an example for the pipeline My-Pipeline-Name and the branch release/my-release-branch-name

Jenkins.instance.getItemByFullName("My-Pipeline-Name/release%2Fmy-release-branch-name").updateNextBuildNumber(BUILD_NUMBER)

I was able to find out about this by running the following command which will list the different jobs (branches) for your pipeline

Jenkins.instance.getItem("My-Pipeline-Name").getAllJobs()

Hope it helps.


Perhaps a combination of these plugins may come in handy:

  • Parametrized build plugin - define some variable which holds your build number
  • Version number plugin - use the variable to change the build number
  • Build name setter plugin - use the variable to change the build number