Download the PHP package ondram/ci-detector without Composer

On this page you can find all versions of the php package ondram/ci-detector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package ci-detector

CI Detector

Latest Stable Version Packagist Downloads Coverage Status GitHub Actions Build Status Travis Build Status AppVeyor Build Status

PHP library to detect continuous integration environment and to read information of the current build.

Why

This library is useful if you need to detect whether some CLI script/tool is running in an automated environment (on a CI server). Based on that, your script may behave differently. For example, it could hide some information which relevant only for a real person - like a progress bar.

Additionally, you may want to detect some information about the current build: build ID, git commit, branch etc. For example, if you'd like to record these values to log, publish them to Slack, etc.

How

The detection is based on environment variables injected to the build environment by each CI server. However, these variables are named differently in each CI. This library contains adapters for many supported CI servers to handle these differences, so you can make your scripts (and especially CLI tools) portable to multiple build environments.

Supported continuous integration servers

These CI servers are currently recognized:

If your favorite CI server is missing, feel free to send a pull-request!

Installation

Install using Composer:

Example usage

API methods reference

Available methods of CiInterface instance (returned from $ciDetector->detect()):

Method Example value Description
getCiName() GitHub Actions Name of the CI server.
The value is one of CiDetector::CI_* constants.
getBuildNumber() 33 Get number of this concrete build.
Build number is usually human-readable increasing number sequence. It should increase each time this particular job was run on the CI server. Most CIs use simple numbering sequence like: 1, 2, 3... However, some CIs do not provide this simple human-readable value and rather use for example alphanumeric hash.
getBuildUrl() https://github.com/OndraM/ci-detector/commit/abcd/checks
or empty string
Get URL where this build can be found and viewed or empty string if it cannot be determined.
getCommit() b9173d94(...) Get hash of the git (or other VCS) commit being built.
getBranch() my-feature
or empty string
Get name of the git (or other VCS) branch which is being built or empty string if it cannot be determined.
Use getTargetBranch() to get name of the branch where this branch is targeted.
getTargetBranch() main
or empty string
Get name of the target branch of a pull request or empty string if it cannot be determined.
This is the base branch to which the pull request is targeted.
getRepositoryName() OndraM/ci-detector
or empty string
Get name of the git (or other VCS) repository which is being built or empty string if it cannot be determined.
This is usually in form "user/repository", for example OndraM/ci-detector.
getRepositoryUrl() https://github.com/OndraM/ci-detector
or empty string
Get URL where the repository which is being built can be found or empty string if it cannot be determined.
This is either HTTP URL like https://github.com/OndraM/ci-detector but may be a git ssh url like ssh://[email protected]/OndraM/ci-detector
isPullRequest() TrinaryLogic instance Detect whether current build is from a pull/merge request.
Returned TrinaryLogic object's value will be true if the current build is from a pull/merge request, false if it not, and maybe if we can't determine it (see below for what CI supports PR detection).
Use condition like if ($ci->isPullRequest()->yes()) { /*...*/ } to use the value.
describe() [...]
(array of values)
Return key-value map of all detected properties in human-readable form.

Supported properties of each CI server

Most CI servers support (✔) detection of all information. However some don't expose necessary environment variables, thus reading some information may be unsupported (❌).

CI server Constant of CiDetector is​PullRequest get​Branch get​Target​Branch get​Repository​Name get​Repository​Url get​Build​Url
AppVeyor CI_APPVEYOR
AWS CodeBuild CI_AWS_CODEBUILD
Azure Pipelines CI_AZURE_PIPELINES
Bamboo CI_BAMBOO
Bitbucket Pipelines CI_BITBUCKET_PIPELINES
Buddy CI_BUDDY
CircleCI CI_CIRCLE
Codeship CI_CODESHIP
continuousphp CI_CONTINUOUSPHP
drone CI_DRONE
GitHub Actions CI_GITHUB_ACTIONS
GitLab CI_GITLAB
Jenkins CI_JENKINS
SourceHut CI_SOURCEHUT
TeamCity CI_TEAMCITY
Travis CI CI_TRAVIS
Wercker CI_WERCKER

Testing

Check codestyle, static analysis and run unit-tests:

To automatically fix codestyle violations run:

Standalone CLI version

If you want to use CI Detector as a standalone CLI command (ie. without using inside code of PHP project), see ci-detector-standalone repository, where you can download CI Detector as a standalone PHAR file with simple command line interface.

Changelog

For latest changes see Semantic Versioning.

Similar libraries for other languages

Similar "CI Info" libraries exists for some other languages, for example:


All versions of ci-detector with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ondram/ci-detector contains the following files

Loading the files please wait ....