Get git branch name in build process
I wanted to get the current git branch name to build binaries with a filename that contains the branch name. Is that possible in Netbeans(7.1) with ant ?
If you do not want to deal with env variables (as suggested in the solution above) AND if the git command is available from your command line, an alternate solution would be using ANT exec:
<exec executable="git" outputproperty="git.branch"
failifexecutionfails="false">
<arg line="rev-parse --abbrev-ref HEAD"/>
</exec>
<echo message="Current branch: ${git.branch}"/>
(Solution basically combines http://llbit.se/?p=1876 and How to get the current branch name in Git?)
One way you can get the current branch name and set it into the branch_name
env variable is:
branch_name=$(git symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/}
branch_name=${branch_name:-HEAD}
You can put this in a shell script to execute this and store it as an environment variable, and then use this env. variable inside ant.
Source - How to programmatically determine the current checked out Git branch
If netbeans/ant can execute shell commands then this is possible.
See How to programmatically determine the current checked out Git branch on how to get the name of the current branch - you then just need to integrate this in your build scripts so they can use the value.
链接地址: http://www.djcxy.com/p/19508.html上一篇: 找出本地分支正在跟踪哪个远程
下一篇: 在构建过程中获取git分支名称