Skip to main content

How to set next build number in Pipeline job?

Comments

4 comments

  • 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.

    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")

    0
  • 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.

    1
  • 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: https://issues.jenkins-ci.org/browse/JENKINS-44757. 

    0

Please sign in to leave a comment.

About CloudBees Support

Our Support Engineers are available to help with any questions or problems you may have with any of our products.