Seems like
- gradle-git plugin is no more maintained so
GitBranchList
api will not available withGradle-6.6.1
task getBranchName(type: GitBranchList) << {
print getWorkingBranch().name
}
- https://stackoverflow.com/a/36760102/1665592 ... it fails on CI tools(Jenkins) if gradle wrapper isn't invoked from root of project where
.git
dir is. It produces errorfatal: not a git repository (or any of the parent directories): .git
asGradle Wrapper
is invoked by Jenkins Gradle plugin from outside of dir where.git
folder resides.
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
}
Both solutions doesn't work well to detect current git branch using Gradle..
How, can I get branch name properly