如何检测 TeamCity 上的 Gradle 构建是否为 运行?
How to detect if a Gradle build is running on TeamCity?
我的构建脚本中的 Some log messages 仅在 TeamCity 上的 Gradle 构建为 运行 时才相关。如何以编程方式检测 Gradle 构建是否在 TeamCity 上 运行?
这可以使用 environment variables corresponding to TeamCity's server build parameters 来完成,引用:
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.
要在 Gradle 脚本中执行此操作,可以使用 method java.lang.System#getenv(java.lang.String)
:
boolean isOnTeamCity = System.getenv("TEAMCITY_VERSION") != null
Some log messages 仅在 TeamCity 上的 Gradle 构建为 运行 时才相关。如何以编程方式检测 Gradle 构建是否在 TeamCity 上 运行?
这可以使用 environment variables corresponding to TeamCity's server build parameters 来完成,引用:
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.
要在 Gradle 脚本中执行此操作,可以使用 method java.lang.System#getenv(java.lang.String)
:
boolean isOnTeamCity = System.getenv("TEAMCITY_VERSION") != null