Created
December 14, 2013 01:49
-
-
Save lifuzu/7954656 to your computer and use it in GitHub Desktop.
Get the most recent tag from the current branch, which made by 'git tag -a master_1.2.3.123'
This file contains hidden or 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
/* | |
* 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() | |
} | |
/* | |
* Gets the short version name from the latest Git tag | |
*/ | |
def getShortVersionName = { -> | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'describe', '--tags', '--abbrev=0' | |
standardOutput = stdout | |
} | |
return stdout.toString().trim() | |
} | |
task version << { | |
println getVersionName() | |
} | |
task shortVersion << { | |
println getShortVersionName() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
git describe --match
git rev-parse --abbrev-ref HEAD
* --tagsThis command can exactly get the latest tag on the current branch even there are many tags in a same commit.