Created
March 11, 2019 19:34
-
-
Save grumpyshoe/08af3ad1fda72a7dd1edc57d56846ab5 to your computer and use it in GitHub Desktop.
Gradle: how to get git hash in build.gradle
This file contains 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
String getGitHash() { | |
// git hash | |
def command = Runtime.getRuntime().exec("git rev-parse --short HEAD") | |
def result = command.waitFor() | |
if (result != 0) { | |
throw new IOException("Command 'getGitHash()' exited with " + result) | |
} | |
String gitCommitHash = command.inputStream.text.trim() | |
//println("getGitHash() : " + gitCommitHash) | |
return gitCommitHash | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment