ondram/ci-detector
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The ondram/ci-detector is a powerful PHP library for detecting the environment of different continuous integration (CI) servers and providing a common interface to access build information. This potent tool proves useful when you need to verify if a CLI script or tool is running within an automated environment such as a CI server. Based on this detection, your script can be customized to behave differently. For instance, you can hide information typically relevant only to a real person like a status bar, and so forth. Additionally, you can detect specific details about the current build like build ID, git commit, and branch, and log or publish these values if need be.
Using ondram/ci-detector is straightforward, all thanks to Composer. First, you install it using Composer with the command composer require ondram/ci-detector
. The package necessitates PHP 7.1 or above. However, if your PHP version is under 7.1, you can still resort to using the older ci-detector version 2.x. Once installed, you can initiate it in your PHP code using the following snippet.
<?php
$ciDetector = new \OndraM\CiDetector\CiDetector();
if ($ciDetector->isCiDetected()) {
//CI server detected! Write your code here.
} else {
// Not run on CI server.
}
To access specific build information, you can use methods like getCiName()
, getBuildNumber()
, getBranch()
, and more.
In-depth documentation regarding ondram/ci-detector is available in the readme on the GitHub page here. The readme serves as an extensive guide, covering what the CI detector is, why it's valuable, and how to use it. It also elaborates on supported CI servers, installation instructions, code usage examples, and available methods of the CiInterface
instance. You can also find a description of each CiInterface
constant and the various descriptors supported by different CI servers for a comprehensive understanding. If you wish to run tests, automatically fix codestyle violations, or use the CI Detector as a standalone CLI command, the readme has got you covered.