Great post, exactly what I needed! The following can save a few minutes to anyone wanting to use a shell command to bump the build # of another jenkins job:
If you want to change build number via nextBuildNumber file you should "Reload Configuration from Disk" from "Manage Jenkins" page.
30 October 2012 at 02:37
Programatically setting the next build number in Hudson/Jenkins is a useful thing to do if you have a build pipeline. After a bit of research it seems there are 3 main approaches that could be useful in different situations:
Set the nextBuildNumber.txt in your Hudson job's directory
Use environment variables for build number passthrough (see @ruby_gem's post here)
Use the nextBuildNumber Hudson plugin and HTTP POST the build number to it
In this post I'll be looking at option 3 - using the nextBuildNumber Hudson plugin.
Using the nextBuildNumber Hudson plugin
Firstly install the nextBuildNumber plugin. You can now set the next build number for a job manually from the plugin link that appear on the left.
To use this programatically you simulate the manual for submission with a web client. I tested it with FireFox ReST client.
To set the next build number to 999 simply formulate an HTTP POST to your Hudson URL:
e.g. http://myhudsonserver:8080/job/myhudsonjobname/nextbuildnumber/submit
With the form data
nextBuildNumber=999
And the HTTP Content-Type request header
Content-Type: application/x-www-form-urlencoded
If your Hudson is secured you'll need to authenticate your web client too.
That's it! Finally it's worth noting that build numbers in Hudson can only go up!
"Setting the Hudson/Jenkins next build number programatically"
2 Comments -
Great post, exactly what I needed!
The following can save a few minutes to anyone wanting to use a shell command to bump the build # of another jenkins job:
bn=`expr $BUILD_NUMBER + 1`
curl --user "user:pass" --data "nextBuildNumber=$bn" --header "Content-Type: application/x-www-form-urlencoded" http://myhudsonserver:8080/job/myhudsonjobname/nextbuildnumber/submit
19 January 2012 at 09:10
If you want to change build number via nextBuildNumber file you should "Reload Configuration from Disk" from "Manage Jenkins" page.
30 October 2012 at 02:37