Use Git tag in build version

Answered

I would like to use the latest Git tag in my build number.  For example, if my latest Git tag is '1.9.2' and my build counter is 50, I would like the build number to be 1.9.2.50.  I know I can use "git describe --abbrev=0 %build.vcs.number%" in a build step to get the latest Git tag, but I can't quite figure out how to get that value into the build number.

0
2 comments
Avatar
Permanently deleted user

Hello!

Please refer to BuildScriptInteractionwithTeamCity-ReportingBuildNumber on how to change Build parameters from Build Step.

E.g. you should write a cmdline Build Step to define the variable as git command output and print it as Service Message:

on Windows:

"C:\Program Files\Git\bin\git" describe --abbrev=0 %build.vcs.number% --tags > __query.tmp
set /p result=<__query.tmp
del __query.tmp
echo ##teamcity[buildNumber '%%result%%.%build.counter%']

on Linux:

export var1=`git describe --abbrev=0 %build.vcs.number% --tags`
echo "##teamcity[buildNumber '$var1.%build.counter%']"

 

0
Avatar
Permanently deleted user

BTW,

If you use tags as branches in Git, then it can be much simplier - define Build number format as 

%teamcity.build.branch%.%build.counter% 

in Build Configuration | General Settings.

0

Please sign in to leave a comment.