Skip to content

Instantly share code, notes, and snippets.

@caffeinetiger
Last active August 28, 2024 08:28
Show Gist options
  • Save caffeinetiger/d5798f34b2068027012a981a4eb2d61b to your computer and use it in GitHub Desktop.
Save caffeinetiger/d5798f34b2068027012a981a4eb2d61b to your computer and use it in GitHub Desktop.
References: - [How to Clean or Reset build numbers in Jenkins job ? ](https://linuxhelp4u.blogspot.com/2018/03/how-to-clean-or-reset-build-numbers-in.html)

How to reset Jenkins build numbers

Steps

  1. Log into Jenkins server
  2. Navigate to Manage Jenkins
  3. Select Script Console
  4. Copy and adapt snippet from fig.1
  5. Select Run
  6. Check job and build numbers/history should be deleted/gone

fig.1

def jobName = "Enter Job Name"
def job = Jenkins.instance.getItem(jobName)
job.getBuilds().each { it.delete() }
job.nextBuildNumber = 1
job.save()
@anusinh9
Copy link

anusinh9 commented Aug 28, 2024

Hi @caffeinetiger please suggest what should be the mechanism for clearing build numbers in case of multibranch pipeline and also jobs under a folder e.g. myfolder/job_name?

TIA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment