Last active
January 11, 2024 03:54
-
-
Save lordcodes/15b2a4aecbeff7c3238a70bfd20f0931 to your computer and use it in GitHub Desktop.
Gradle function to get the current Git branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getCurrentGitBranch() { | |
def gitBranch = "Unknown branch" | |
try { | |
def workingDir = new File("${project.projectDir}") | |
def result = 'git rev-parse --abbrev-ref HEAD'.execute(null, workingDir) | |
result.waitFor() | |
if (result.exitValue() == 0) { | |
gitBranch = result.text.trim() | |
} | |
} catch (e) { | |
} | |
return gitBranch | |
} |
in my project I have few modules and they are sit on different repositories is it possible to get git branch of each module?
Thanks! 🙏
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot!