Skip to content

Instantly share code, notes, and snippets.

@alf239
Created November 29, 2011 13:14
Show Gist options
  • Save alf239/1404771 to your computer and use it in GitHub Desktop.
Save alf239/1404771 to your computer and use it in GitHub Desktop.
Get git version
def env = System.getenv()
def gitcmd = "git"
if (env["com.apple.java.jvmMode"])
gitcmd = "/usr/local/git/bin/git"
if (env["OS"] =~ /^Windows/)
gitcmd = "cmd /c ${gitcmd}"
def gitDescribe = """${gitcmd} describe""".execute().in.text.trim()
def m = gitDescribe =~ /(?:atlas-)?(.*)/
def gitBranch = """${gitcmd} symbolic-ref -q HEAD""".execute().in.text.trim()
def n = gitBranch =~ /(?:refs\/heads\/)?(.*)/
project.properties["versionDescriptor"] = m[0][1] + '-' + n[0][1]
project.properties["buildDate"] = new Date().getDateTimeString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment