How to pass branch name in MSBuild script in TeamCity?

I have TeamCity creating a configuration in several Mercurial branches. As part of the build process, I want to name some conclusion based on building a branch.

I tried using $(TEAMCITY_BUILD_BRANCH) to try to get the teamcity.build.branch property from TeamCity, but I only get an empty string. I successfully used $(BUILD_NUMBER) to get the build.number property in the script, so I'm a bit confused about what is required.

+4
source share
2 answers

Just create a build option:

 system.branch_name = %teamcity.build.vcs.branch.Your_Project% 

Any non-alpha-numeric characters in the project name must be replaced with "_". In your msbuild, use $(branch_name) to refer to the parameter.

Works like a charm :-)

+4
source

$ (vcsroot_url) if you only have one vcs root connected to build the configuration.

If this is not what you want, try to get all the known properties, as described here: http://confluence.jetbrains.net/display/TCD7/Predefined+Build+Parameters

Server properties for reference only:

You can get the full set of server properties for links only by adding the System.teamcity.debug.dump.parameters property to build the configuration and check "Available server for reference only properties" in the build log.

UPD: Also you can check this "what new" link .

VCS branch option For Git and Mercurial, TeamCity provides additional build options with the VCS branch names known at the time the build started. If the assembly passes validation with refs / heads / bugfix, TeamCity will add a configuration parameter with the following name: teamcity.build.vcs.branch. <simplified VCS root name> = refs / heads / bugfix

Where is the root name of VCS, where all non-alpha numeric characters are replaced with _.

According to this, you should have access to the branches as the next variable msbuild $ (Teamcity_build_vcs_branch _).

Hope this time I understood your problem correctly.

PS: Sorry for the initial erroneous behavior. I did not know about such subtle differences between DVCS and CVCS in TeamCity. Anyway - my initial answer may also help you - you can get all the variables and then find the exact var name with the data you need

+2
source

Source: https://habr.com/ru/post/1439131/


All Articles