Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if test is running on GitLab CI server

I have a test, which is using MySQL database configured and running on gitlab CI server (gitlab-ci.yml). I want that test to be disabled when it's running locally (it's using in-memory database instead). Is there any way to check if the test is running on GitLab Ci server? Something like:

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

Maybe there's environmental variable, which I can check ?

like image 316
RichardK Avatar asked Dec 13 '18 09:12

RichardK


People also ask

Does GitLab run tests?

You can configure your job to use Unit test reports, and GitLab displays a report on the merge request so that it's easier and faster to identify the failure without having to check the entire log. Unit test reports currently only support test reports in the JUnit report format.

How do I run a GitLab CI file locally?

Project Creation on GitLabOpt the Initialize repository with a README option, this creates a README file so that the Git repository is initialised and has a default branch that can be cloned. Click Create project. Now clone the project on local.


1 Answers

Gitlab CI defines a large number of environment variables; you could use e.g. GITLAB_CI.

Something like:

if(System.getenv("GITLAB_CI") != null) {
  Assert.assertThat(...);
}
like image 96
wilddev Avatar answered Sep 30 '22 00:09

wilddev