Software Development

Is it possible to dynamically update or change the Jenkins build number during a job execution?

CH Asked by Christopher Hayes · 12-09-2025
0 upvotes 8,482 views 0 comments
The question

I am looking for a way to modify the Jenkins build number from within the pipeline execution itself. Currently, Jenkins increments the build number automatically, but for our release tagging strategy, we need the build number to align with a specific versioning logic. Is there a plugin or a Groovy script that allows me to override the BUILD_NUMBER environment variable or set the next build number programmatically so it stays consistent with our internal tracking?

3 answers

0
AM
Answered on 13-09-2025

To change the current build number during execution, you generally use the "Next Build Number" plugin, as Jenkins treats the current build ID as immutable once the process starts. However, you can use a Groovy script in the Jenkins script console or a pipeline stage to set the next build ID for future runs. For the current run, most people use the currentBuild.displayName property to change how the build appears in the history. This allows you to append version strings or custom identifiers without breaking the underlying filesystem structure that Jenkins relies on for build metadata.

0
JO
Answered on 15-09-2025

Are you trying to change the actual integer ID in the filesystem, or are you just looking to make the UI display a specific version string like 1.0.4-beta?

JO 15-09-2025

If you only need the UI to look different, use currentBuild.displayName = "Your-Version-Number". If you actually need to skip numbers or reset the counter, you must use Jenkins.instance.getItem('JobName').updateNextBuildNumber(Integer.parseInt(newNumber)). Note that this requires admin permissions and should be done carefully to avoid build collisions in your job history.

0
KI
Answered on 17-09-2025

I usually just update the display name in my Jenkinsfile. It is much safer than trying to force the internal counter to change mid-stream.

CH 18-09-2025

I agree with Amanda and Christopher. Overriding the internal build ID often causes issues with plugins that track history. Stick to changing the display name for visibility.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session