Created
October 27, 2016 21:57
-
-
Save lordcodes/8afe89bbf430523a0fb2ab254a29b7df to your computer and use it in GitHub Desktop.
Gradle function to get the current Git commit
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
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