Skip to content

Instantly share code, notes, and snippets.

@lordcodes
Created October 27, 2016 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lordcodes/8afe89bbf430523a0fb2ab254a29b7df to your computer and use it in GitHub Desktop.
Save lordcodes/8afe89bbf430523a0fb2ab254a29b7df to your computer and use it in GitHub Desktop.
Gradle function to get the current Git commit
def getCurrentGitCommitHash() {
def gitCommit = "Unknown commit"
try {
def workingDir = new File("${project.projectDir}")
def result = 'git rev-parse --short HEAD'.execute(null, workingDir)
result.waitFor()
if (result.exitValue() == 0) {
gitCommit = result.text.trim()
}
} catch (e) {
}
return gitCommit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment