Wednesday, March 25, 2015

Change a Build Number in Jenkins

So you want to change a build number in Jenkins ... I searched the web all over the place and it's not out there.  So here it is.  Many people ask the question, but mostly ridiculous answers exist, mainly in the form of "You don't want to do that" or "Why would you want to do that?"  This is not helpful.

Although I admit that most of the reasons for needing to do this are probably misguided - even my own -- there may arise a legitimate need to do this.

Mine arises because the build (misguidedly) uses the Jenkins internal build number as part of the jar/Artifactory version string and I have moved the build to a new Jenkins server.  Doing this effectively resets the build number to one, which will result in overwriting an existing artifact on the repository.

To change the build number.  Change directories to the Jenkins job directory on the master.

cd  {path_to_jenkins_master_home}/jobs/{job_name}

Edit the file nextBuildNumber and change (advance -- I am not sure you can go backwards) the build number to the one you want to use.   Shelve the build and unshelve it to reload the job from the disk.  This allows reloading the job without restarting Jenkins.

When I ran the job it produced an error regarding the lastSuccessful and lastStable directories -- located in the same directory -- not being empty so I had to move those out of the way, at which point the next build correctly ran. 


No comments: