0

We have a Jenkins job running on a Jenkins server instance A. The current build number for this job is say 58.

We are migrating this Jenkins job to a new Jenkins server - B. However, there is a need to retain the build number - 58 from the previous server in this new Jenkins instance B.

Is this possible? If yes, how?

Thank you

sumant
  • 127
  • 1
  • 3
  • 11

2 Answers2

0

If you only intend to keep the build number intact for job the in the new Jenkins Server, you could achieve it simply by writing a script that will populate the nextBuildNumber file in $JENKINS_HOME/jobs/<job_name>/ with the appropriate #buildnumber that you wish to have.

Something like this (script.sh) :-

#!bin/bash -x
JENKINS_HOME=/var/lib/jenkins
mkdir -p $JENKINS_HOME/jobs/<new_job> && cp $JENKINS_HOME/jobs/<old_job>/* $JENKINS_HOME/jobs/<new_job>/
OLD_BUILD_NO=`cat $JENKINS_HOME/jobs/seed/nextBuildNumber`
NEW_BUILD_NO=`expr $OLD_BUILD_NO - 1`
echo $NEW_BUILD_NO > $JENKINS_HOME/jobs/<new_job>/nextBuildNumber
chown -R jenkins:jenkins $JENKINS_HOME/jobs/temp/

Now run this script as:-

sudo bash script.sh

Although it creates the required job in the same jenkins server instance, the basic idea is same ..to populate the nextBuildNumber file.

prvn
  • 684
  • 6
  • 21
  • Thank you. I believe the other option is to install a Jenkins plugin 'Next build number' but that is ruled out in our enterprise. This works as a reference to start now. Thank you – sumant Jan 20 '16 at 21:43
0

The accepted answer to modify the nextBuildNumber File sadly didn't work for me, but found this answer by jayan in another Stackoverflow question:

https://stackoverflow.com/a/34951963

Try running below script in Jenkins Script Console.. Change "workFlow" to your

Jobname

def job = Jenkins.instance.getItem("workFlow")
job.nextBuildNumber = 10
job.saveNextBuildNumber()
Sawor
  • 1
  • 1