I want to have the current Git branch in the Version name of my Android app. I built in this snippet from here into my build.gradle
:
def getWorkingBranch() {
// Triple double-quotes for the breaklines
def workingBranch = """git --git-dir=${rootDir}/git
--work-tree=${rootDir}/..
rev-parse --abbrev-ref HEAD""".execute().text.trim()
print "Working branch: " + workingBranch
return workingBranch
}
The snippet is slightly altered as suggested in the first comment on the article.
It works fine when I build my app locally, but doesn't when the app is built with Jenkins
. I also tried the original variant of the snippet, in both cases the workingBranch
String is empty.
Jenkins seems to be 'aware' of the branch it builds, it lists the branches under
Git Build Data / Built Branches
, so it should be possible