How to increase jenkins build number automatically or by using shell script?? For now i am doing the same using configure option, and increasing manually. i want to do it automatically.
What you are asking for (i.e. keeping the build number same between multiple jobs) is simply impossible in Jenkins. This is done by design (as noted by Jenkins creator himself): "[JENKINS] assumes that the build number is unique and monotonic."
. You can change it to a higher value, but changing it to same number will outright break Jenkins and is therefore not possible.
Build run number is just that: a run number.
It is supposed to be sequential.
It is not a version number in any way.
There are several ways to get versioning information into the build history however.
Description Setter Plugin
This is what I use. It doesn't change the build number, but rather the description, which is done automatically. Furthermore, since this is a description, it can also be modified manually at any time.
This is what it looks like:
Note that builds #50
and #51
actually have the same version 1.3.0.394376
.
In that version string, the 1.3.0
is the current release number, as determined by the project properties, while the 394376
is actually an SVN revision number, obtained from $SVN_REVISION_1
build variable. So every time there is a new commit in SVN, I get a new revision number. But if there are no commits and the job is rebuilt for whatever reason (like in #50
and #51
), my version number remains same, as there was no code change.
The way I have it configured is:
echo Version is: ${internalVersionNumberFromWherever}.${SVN_REVISION_1}
Version is: (.*)
(.*)
will be used as description.Build - \1
. Where \1
is a reference to first group (.*)
from the RegEx.* Note that if your build fails before the step that outputs the version text, the description setter plugin will not be able to pick it up. If you always want to see the version, then setup the display of version number as the very first step.
Build Name Setter plugin
This plugin will actually change the build number
However remember the limitation that each build number has to be unique.
Best way to ensure that is to add ${BUILD_NUMBER}
to whatever arbitrary number that you want (like in the image above). This way you can have builds numbers like 50.123
and then 50.124
where 50
is your version while 123
and 124
are sequential build run numbers, and Jenkins makes sure of keeping the ${BUILD_NUMBER}
unique.
Finally, there is the Version Number plugin which I haven't personally tried, but it may help you.
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