Some log messages in my build scripts are only relevant when the Gradle build is running on TeamCity. How do detect programmatically if the Gradle build is running on TeamCity or not?
Some log messages in my build scripts are only relevant when the Gradle build is running on TeamCity. How do detect programmatically if the Gradle build is running on TeamCity or not?
This can be done using environment variables corresponding to TeamCity's server build parameters, quote:
Environment variable name Description TEAMCITY_VERSION The version of the TeamCity server. This property can be used to determine if the build is run within TeamCity.
To do it in a Gradle script, method java.lang.System#getenv(java.lang.String) can be used:
boolean isOnTeamCity = System.getenv("TEAMCITY_VERSION") != null