Skip to content

Instantly share code, notes, and snippets.

@nightcrawler-
Created April 14, 2020 17:10
Show Gist options
  • Save nightcrawler-/7da21778262b1ccb929c68a4db496558 to your computer and use it in GitHub Desktop.
Save nightcrawler-/7da21778262b1ccb929c68a4db496558 to your computer and use it in GitHub Desktop.
// Gets the version code -- number of git tags to this end
def getVersionCode = { ->
try {
def code = new ByteArrayOutputStream()
exec {
commandLine 'git', 'tag', '--list'
standardOutput = code
}
return code.toString().split("\n").size()
}
catch (ignored) {
return -1
}
}
// Gets the version name from the latest Git tag
def getVersionName = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags', '--dirty'
standardOutput = stdout
}
return stdout.toString().trim()
}
catch (ignored) {
return null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment