<exec executable="git" outputproperty="build.commit">
<arg value="describe"/>
<arg value="--tags"/>
<arg value="--abbrev=20"/>
</exec>
Now you can get result value of git describe from ${build.commit}.
Credit: How to lookup the latest git commit hash from an ant build script - Stack Overflow
But there is also some problems with Hudson's git plug-in which it always tags build revision that causes our git describe return the wrong result. There was someone send patch to fix this but this is not build to the plug-in yet. Currently workaround is provided in that patch page, add paramter to git describe, "--match=[^(hudson)]*", to ignore tag from Hudson. So we have to add more arg line to Ant's exec task:
<arg value="--match=[^(hudson)]*">
That's all.
No comments:
Post a Comment