Skip to content

Instantly share code, notes, and snippets.

@lifuzu
Last active December 31, 2015 16:29
Show Gist options
  • Save lifuzu/8013767 to your computer and use it in GitHub Desktop.
Save lifuzu/8013767 to your computer and use it in GitHub Desktop.
Gets the version name from the latest Git tag
/*
* Get the current branch name
*/
def getCurrentBranchName = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'symbolic-ref', 'HEAD', '--short'
standardOutput = stdout
}
return stdout.toString().trim()
}
/*
* Gets the version name from the latest Git tag
*/
def getVersionName = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags'
standardOutput = stdout
}
return stdout.toString().trim()
}
/*
Reference:
http://ryanharter.com/blog/2013/07/30/automatic-versioning-with-git-and-gradle/
*/
@lifuzu
Copy link
Author

lifuzu commented Jan 30, 2014

How to call it?

retval = getVersionName()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment