How to auto increment a variable for every Jenkins Build

32 views
Skip to first unread message

Faad Sayaou

unread,
Jan 24, 2019, 1:12:30 PM1/24/19
to Jenkins Users
Hello everyone,

I would like to auto increment a number for every Jenkins build.  I have a function which reads value (1.0.0.0) from a file which goes as follows 


String IncBuildNum() {

def v= getVersion("path/to/file.xml")

def splitted= v..split('\\.')
splitted[3]= (((splitted[3] +1 as BigDecimal) + 1 ) as String)

return splitted.join('.')
}

However, I will like to increase this number 1 for every Jenkins build. Right now 
Is this possible?

Justin Harringa

unread,
Jan 24, 2019, 3:01:39 PM1/24/19
to Jenkins Users
Any reason you couldn't use the BUILD_NUMBER environment variable for this?

Faad Sayaou

unread,
Jan 24, 2019, 3:09:42 PM1/24/19
to Jenkins Users
The build number gets really large which is something we do not want. Would have been good if there was a way to reset it. 

Justin Harringa

unread,
Jan 24, 2019, 3:13:23 PM1/24/19
to jenkins...@googlegroups.com
You can change nextBuildNumber but there are some implications there. Sounds like you're not only looking for an incrementer but a semantic version handler. You do get new build numbers with multi-branch. I could see something like that working by using a branching strategy for each semantic major.minor release where build number is the patch version.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/LfbCVSYZIx8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/8db59767-f91c-400e-a012-6a46db036261%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages