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.
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:
pass it to your build tool (Gradle, I assume) via CLI, something like this:
... -Dteamcity.build.branch=%teamcity.build.branch%
Then I suppose you'll be able to process it in the build script like you already do.
make it an environment variable so that your build can pick it up. This could also be done in two ways:
env.
, e.g. env.APP_VERSION
and set it to %teamcity.build.branch%
or whatever pattern you useAPP_VERSION=%teamcity.build.branch% gradle ...
In these cases, you can use something like System.getenv('APP_VERSION')
to use it.
if you use Gradle build runner, you can use gradle.properties
and refer an env.
or system.
parameter as per the documentation below. You'll need to create the corresponding property in your build configuration and set it to your value containing %teamcity.build.branch%
.
The Configuring build parameters section of TeamCity documentation has more details about this.