How can I get the current git branch in gradle?

You also are able to get git branch name without the plug-in.

def gitBranch() {
    def branch = ""
    def proc = "git rev-parse --abbrev-ref HEAD".execute()
    proc.in.eachLine { line -> branch = line }
    proc.err.eachLine { line -> println line }
    proc.waitFor()
    branch
}

Refer to: Gradle & GIT : How to map your branch to a deployment profile

Leave a Comment