Last active
December 21, 2015 07:59
-
-
Save mawaldne/6275270 to your computer and use it in GitHub Desktop.
Utility method to update semantic version number. Useful when tagging a new version.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def updateBuildVersion(currentVersion, updateType) { | |
def versionMatcher = currentVersion =~ /^(\d+)\.(\d+)\.(\d+)$/ | |
def major = versionMatcher[0][1].toInteger() | |
def minor = versionMatcher[0][2].toInteger() | |
def patch = versionMatcher[0][3].toInteger() | |
if (updateType == 'patch') | |
patch += 1 | |
else if (updateType == 'minor') | |
minor += 1 | |
else if (updateType == 'major') | |
major += 1 | |
else return | |
def newVersion = "${major}.${minor}.${patch}" | |
println "Updating current version ${currentVersion} to ${newVersion}" | |
return newVersion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment