【发布时间】:2021-11-09 00:11:11
【问题描述】:
我的构建脚本中的Some log messages 仅在 Gradle 构建在 TeamCity 上运行时才相关。如何以编程方式检测 Gradle 构建是否在 TeamCity 上运行?
【问题讨论】:
我的构建脚本中的Some log messages 仅在 Gradle 构建在 TeamCity 上运行时才相关。如何以编程方式检测 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
【讨论】: