Skip to content

Instantly share code, notes, and snippets.

@mawaldne
Last active December 21, 2015 07:59
Show Gist options
  • Save mawaldne/6275270 to your computer and use it in GitHub Desktop.
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.
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