androidgradlegroovyteamcity

How to get a teamcity.build.branch from TeamCity


I need to retrieve the value of teamcity.build.branch and use it for versionName of ANDROID app. I'm attempting to access this parameter using the following methods:

    project.findProperty("teamcity.build.branch")
    
    if (hasProperty("teamcity")) {
        teamcity["teamcity.build.number"]
         or 
        teamcity["vcsroot.branch"]
    }
    
    System.getenv('teamcity.build.branch')

However, none of these methods are working for me.

I tried logging all the properties from System.getenv and project.properties, but I couldn't find the 'branch' property.

In the TeamCity properties tab, I can see teamcity.build.branch, so the property exists, but I can't find the method to access it.


Solution

  • It's not an environment variable (so it couldn't be picked up by System.getenv), and it's not a system. property so it's not getting automatically passed to the build runner.

    You have several options:

    The Configuring build parameters section of TeamCity documentation has more details about this.