Skip to content

Instantly share code, notes, and snippets.

@tsengvn
Created May 30, 2017 10:16
Show Gist options
  • Save tsengvn/d7c7d4bc235489a83a99c1eb9b2912d5 to your computer and use it in GitHub Desktop.
Save tsengvn/d7c7d4bc235489a83a99c1eb9b2912d5 to your computer and use it in GitHub Desktop.
def getVersionName = { ->
def hashStdOut = new ByteArrayOutputStream()
exec {
commandLine "git", "rev-parse", "--short", "HEAD"
standardOutput = hashStdOut
}
def buildNumberStdOut = new ByteArrayOutputStream()
exec {
commandLine 'echo', "$BUILD_NUMBER"
standardOutput = buildNumberStdOut
}
return buildNumberStdOut.toString().trim() + '-' + hashStdOut.toString().trim()
}
def getVersionName2() {
return "echo $BUILD_NUMBER".execute().text.trim() +
"-" +
"git rev-parse --short HEAD".execute().text.trim()
}
task printGitVersionName {
doLast {
println getVersionName()
println getVersionName2()
}
}
// execute as "./gradlew -q printGitVersionName -PBUILD_NUMBER=457"
@pavi2410
Copy link

Thanks for this! getVersionName2() works so perfectly

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