How to set next build number in Pipeline job?


How do I set the next build number of a Pipeline job?



You can run the following from the Script Console ($JENKINS_URL/script):

def job = Jenkins.instance.getItemByFullName("folderName/my-pipeline-job")
job.nextBuildNumber = 10

Replace folderName/my-pipeline-job with your folder/job name and 10 with the desired next build number.

Have more questions?


  • 0
    Ed Meagher

    My jobs are in folders and in order to change the build number on them I did the following:

        job = Jenkins.getInstance().getItemByFullName("my-folder-name/my-job-name", Job.class)
        job.nextBuildNumber = 92

    I'm not sure why the 'getItem(jobname)' wouldn't find the job even when I specified the folder.

    Edited by Ed Meagher
  • 0
    James Morgan

    JFYI, using getItem() you'd need to do (for the same result of course):
    job = Jenkins.getItem("my-folder-name").getItem("my-job-name")

  • 1
    Steven Christou

    Hello James and Ed,


    I updated the article to use getItemByFullName. The getItem method only will search at the top level of a project, however if you have items in any subfolders (2* levels) it will not search.




  • 0
    Derrik Ammons

    I couldn't get this to work in my scenario.  Will this work if the build has already been kicked off from a multibranch pipeline script? I want to reset the build back to 1 if the version is greater than the previous version.  I posted a Jira ticket for Jenkins: 

Please sign in to leave a comment.