Skip to content

Instantly share code, notes, and snippets.

@rajajawahar
Created April 2, 2019 06:32
Show Gist options
  • Save rajajawahar/85b6663422cf0254786edbe819952fec to your computer and use it in GitHub Desktop.
Save rajajawahar/85b6663422cf0254786edbe819952fec to your computer and use it in GitHub Desktop.
//Other methods
def getGitHash() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
def static getCommitMessages() {
def gitlog = 'git log origin/develop...HEAD --decorate'.execute().text
if (gitlog.trim().length() > 0) return gitlog
return 'git log -n 1 --decorate'.execute().text
}
// Export methods by turning them into closures
ext {
getGitHash = this.&getGitHash
getCommitMessages = this.&getCommitMessages
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment