I am trying to set the next build number for our release branch programmatically but I'm facing an issue.
Below are the two ways I tried it:
def job = Jenkins.instance.getItem("master")
job.nextBuildNumber = env.BUILD_NUMBER + 1
job.saveNextBuildNumber()
I tried using CLI
command also:
java -jar ${env.HOME} jenkins-cli.jar -s XX-JENKINS-SERVER" set-next-build-number 'Pipeline/master' 44
But no luck.
Please guide me how to set up next build number for multibranch pipeline.
Head over to your Jenkins instance and create a new item. Enter a name for the job, and select the “Multibranch Pipeline” option at the end of the screen. Then, click on the OK button. In the next screen, go to the “Branch sources” tab, click on the “Add source” button, and choose “Git” from the dropdown menu.
If you want to add new parameters you have to do it using properties in Jenkinsfile - goto <JENKINS URL>/pipeline-syntax and generate code for the properties step.
The Multibranch Pipeline project type enables you to implement different Jenkinsfiles for different branches of the same project. In a Multibranch Pipeline project, Jenkins automatically discovers, manages and executes Pipelines for branches which contain a Jenkinsfile in source control.
You absolutely can do this, and I just did to test it. If you go into the actual page for the specific branch of your pipeline job you want to change, note the "Full project name:" near the top, below the title.
Then, follow the instructions from this other StackOverflow thread:
Jenkins.instance.getItemByFullName("My-Build-Pipeline/feature%2FABC-9-improve-build").updateNextBuildNumber(47)
In the above example, my "full project name" was:
My-Build-Pipeline/feature%2FABC-9-improve-build
I tried to use the "Next Build Number" plugin also mentioned in that thread, but it didn't work for my multibranch pipeline job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With