1

How can i update the version build number everyday. I have a version format "${BUILD_TIMESTAMP}.${BUILDS_ALL_TIME}", my build version are based on the date and the build number.

 So i want to reset (or make it start from 1) the Build number everyday as the date changes.

Ex: If today i have five builds then the version will "2019-09-10.5" and for tomorrow the if its the first build then i want the value to be "2019-09-11.1" but using the above values i'm getting the next build number in the next day build. i.e version="2019-09-11.6"

So How can i reset or make it to 1 every next day for the first Build.

Have tried using different options of the version build number but nothing worked as per my requirement

GangaRam Dewasi
  • 631
  • 7
  • 11

1 Answers1

0

You need to create another pipeline job with below mentioned content:

node() { stage('Cleaning the Jenkins project history'){ def myJob = Jenkins.instance.getItem('job_name_to_reset') myJob.getBuilds().each { it.delete() } myJob.nextBuildNumber = 1 myJob.save() } }

Schedule this job to run everyday at midnight and it will delete the build history and reset the count to 0. Note: You need to deselect Use Groovy Sandbox option otherwise it will ask for script approval each time.

OR

If you don't want to delete the build history, then you can go with this approach: Changing Jenkins build number

  • But this will delete my build history as well, as i only need to reset every next the value of the "$BUILDS_ALL_TIME" or any other option/script kind that can be used to reset the minor version value. – GangaRam Dewasi Sep 11 '19 at 18:30
  • I don't believe there's a need to delete the existing builds. Just reset the nextBuildNumber; see [Changing Jenkins build number](https://stackoverflow.com/q/19645430/598141) – Ian W Sep 12 '19 at 08:10
  • Agreed with @IanW – Rajnikant Jaybhaye Sep 13 '19 at 06:38
  • @RajnikantJaybhaye, then perhaps edit your answer, so he can mark as "answered" :) – Ian W Sep 13 '19 at 06:48