Thanks Benjamin! I ended up doing something simpler:
task buildInfo {
def cmd = "git rev-parse --short HEAD"
def proc = cmd.execute()
ext.revision = proc.text.trim()
ext.timestamp = (int)(new Date().getTime()/1000)
}
Then I can just add this task as a dependency where needed and access the build information via the task properties.