【问题标题】:How to detect if test is running on GitLab CI server如何检测测试是否在 GitLab CI 服务器上运行
【发布时间】:2019-05-14 11:14:02
【问题描述】:

我有一个测试,它使用在 gitlab CI 服务器 (gitlab-ci.yml) 上配置和运行的 MySQL 数据库。我希望在本地运行时禁用该测试(它使用的是内存数据库)。有什么方法可以检查测试是否在 GitLab Ci 服务器上运行?比如:

if(isRunningOnGitlabCi()) {
  Assert.assertThat(...);
}

也许有环境变量,我可以检查一下?

【问题讨论】:

    标签: java gitlab gitlab-ci


    【解决方案1】:

    Gitlab CI defines a large number of environment variables;你可以使用例如GITLAB_CI.

    类似:

    if(System.getenv("GITLAB_CI") != null) {
      Assert.assertThat(...);
    }
    

    【讨论】:

    • 只是指出这对python有效,它帮助了我很多,谢谢!
    猜你喜欢
    • 2014-07-07
    • 2017-05-25
    • 2021-09-28
    • 2015-10-24
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    相关资源
    最近更新 更多