Skip to content

Instantly share code, notes, and snippets.

@grumpyshoe
Created March 11, 2019 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save grumpyshoe/08af3ad1fda72a7dd1edc57d56846ab5 to your computer and use it in GitHub Desktop.
Save grumpyshoe/08af3ad1fda72a7dd1edc57d56846ab5 to your computer and use it in GitHub Desktop.
Gradle: how to get git hash in build.gradle
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