Gradle – How to execute git command from build.gradle

gradlegroovy

Could you guys clarify why

def getBuildSuffix() {
  return 'git rev-list HEAD | wc -l | tr -d " "'.execute().text.trim()
}

returns nothing to me taking into consideration there is data when you run git command from a command line:

prototype (master) $ git rev-list HEAD | wc -l | tr -d " "
72

May be I'm just executing a git command from my build.gradle in a wrong way?

Best Solution

Pipe is a shell feature so you need to go like:

['sh', '-c', 'git rev-list HEAD | wc -l | tr -d " "'].execute().text.trim()
Related Question