From 8161708dd51bd45fa2a3442b019aac779a3247a4 Mon Sep 17 00:00:00 2001 From: Ondrej Machulda Date: Fri, 22 May 2015 23:25:23 +0200 Subject: [PATCH] Detect other CI server besides Jenkins --- src/Console/Command/Command.php | 24 ++++++++++++++++++++++++ src/Console/Command/InstallCommand.php | 2 +- src/Console/Command/RunTestsCommand.php | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Console/Command/Command.php b/src/Console/Command/Command.php index 57c93559..ab370683 100644 --- a/src/Console/Command/Command.php +++ b/src/Console/Command/Command.php @@ -35,4 +35,28 @@ public function getDispatcher() { return $this->dispatcher; } + + /** + * Check if current environment is CI server. + * + * @codeCoverageIgnore The environment variables behavior is untestable + * @return bool|string False if not an CI server, name of the CI server otherwise + */ + protected function isCi() + { + $ciEnvVariables = [ + 'JENKINS_URL' => 'Jenkins CI', + 'TRAVIS' => 'Travis CI', + 'CIRCLECI' => 'CircleCI', + 'TEAMCITY_VERSION ' => 'TeamCity', + ]; + + foreach ($ciEnvVariables as $variable => $ciName) { + if (getenv($variable)) { + return $ciName; + } + } + + return false; + } } diff --git a/src/Console/Command/InstallCommand.php b/src/Console/Command/InstallCommand.php index 657b8879..7ec3a879 100644 --- a/src/Console/Command/InstallCommand.php +++ b/src/Console/Command/InstallCommand.php @@ -118,7 +118,7 @@ function ($answer) use ($latestVersionErrorMsg) { sprintf( 'Steward %s is now downloading the Selenium standalone server...%s', $this->getApplication()->getVersion(), - (!getenv('JOB_NAME') ? ' Just for you <3!' : '') + (!$this->isCi() ? ' Just for you <3!' : '') ) ); } diff --git a/src/Console/Command/RunTestsCommand.php b/src/Console/Command/RunTestsCommand.php index 08b1aad9..e4f54a88 100644 --- a/src/Console/Command/RunTestsCommand.php +++ b/src/Console/Command/RunTestsCommand.php @@ -142,7 +142,7 @@ protected function execute(InputInterface $input, OutputInterface $output) sprintf( 'Steward %s is running the tests...%s', $this->getApplication()->getVersion(), - (!getenv('JOB_NAME') ? ' Just for you <3!' : '') // in jenkins it is not just for you + (!$this->isCi() ? ' Just for you <3!' : '') // on CI server it is not just for you ) );