【问题标题】:How to detect if a Gradle build is running on TeamCity?如何检测 Gradle 构建是否在 TeamCity 上运行?
【发布时间】:2021-11-09 00:11:11
【问题描述】:

我的构建脚本中的Some log messages 仅在 Gradle 构建在 TeamCity 上运行时才相关。如何以编程方式检测 Gradle 构建是否在 TeamCity 上运行?

【问题讨论】:

    标签: gradle teamcity


    【解决方案1】:

    这可以使用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
    

    【讨论】:

      猜你喜欢
      • 2010-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-27
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      • 2019-10-06
      相关资源
      最近更新 更多