How to set next build number in Pipeline job

Issue

Next Build Number Plugin does not work with Pipeline jobs. How do I set next build number?

Environment

  • CloudBees Jenkins Enterprise

Resolution

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

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

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

Have more questions? Submit a request

3 Comments

  • 0
    Avatar
    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
        job.save()

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

    Edited by Ed Meagher
  • 0
    Avatar
    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
    Avatar
    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.

     

    Thanks,

    Steve.

Please sign in to leave a comment.