{"id":15470413,"url":"https://github.com/ondram/ci-detector","last_synced_at":"2025-05-14T18:05:15.848Z","repository":{"id":10107881,"uuid":"64503246","full_name":"OndraM/ci-detector","owner":"OndraM","description":"Detect continuous integration environment and get information of current build","archived":false,"fork":false,"pushed_at":"2024-11-28T14:09:10.000Z","size":280,"stargazers_count":217,"open_issues_count":3,"forks_count":12,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-09T07:49:25.868Z","etag":null,"topics":["appveyor","build-automation","ci","ci-info","circleci","codeship","continuous-integration","gitlab","jenkins","php","travis","travis-ci"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OndraM.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-29T18:45:37.000Z","updated_at":"2025-02-04T08:41:25.000Z","dependencies_parsed_at":"2023-11-23T11:22:44.670Z","dependency_job_id":"b954feb6-fcef-4c00-b2db-40232b5aabf1","html_url":"https://github.com/OndraM/ci-detector","commit_stats":{"total_commits":189,"total_committers":11,"mean_commits":"17.181818181818183","dds":"0.12698412698412698","last_synced_commit":"cb1a9472aab69c81843975ca1c4e1c1dfb857353"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OndraM%2Fci-detector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OndraM%2Fci-detector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OndraM%2Fci-detector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OndraM%2Fci-detector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OndraM","download_url":"https://codeload.github.com/OndraM/ci-detector/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254198514,"owners_count":22030965,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appveyor","build-automation","ci","ci-info","circleci","codeship","continuous-integration","gitlab","jenkins","php","travis","travis-ci"],"created_at":"2024-10-02T02:04:33.310Z","updated_at":"2025-05-14T18:05:10.839Z","avatar_url":"https://github.com/OndraM.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CI Detector\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/ondram/ci-detector.svg?style=flat-square)](https://packagist.org/packages/ondram/ci-detector)\n[![Packagist Downloads](https://img.shields.io/packagist/dt/OndraM/ci-detector?style=flat-square)](https://packagist.org/packages/ondram/ci-detector)\n[![Coverage Status](https://img.shields.io/coveralls/OndraM/ci-detector/main.svg?style=flat-square)](https://coveralls.io/r/OndraM/ci-detector)\n[![GitHub Actions Build Status](https://img.shields.io/github/actions/workflow/status/OndraM/ci-detector/tests.yaml?style=flat-square\u0026label=GitHub%20Actions%20build)](https://github.com/OndraM/ci-detector/actions)\n[![Travis Build Status](https://img.shields.io/travis/com/OndraM/ci-detector.svg?style=flat-square\u0026label=Travis%20build)](https://app.travis-ci.com/OndraM/ci-detector)\n[![AppVeyor Build Status](https://img.shields.io/appveyor/ci/OndraM/ci-detector.svg?style=flat-square\u0026label=AppVeyor%20build)](https://ci.appveyor.com/project/OndraM/ci-detector)\n\nPHP library to detect continuous integration environment and to read information of the current build.\n\n## Why\n\nThis library is useful if you need to detect whether some CLI script/tool is running in an automated environment (on a CI server).\nBased on that, your script may behave differently. For example, it could hide some information which relevant only for\na real person - like a progress bar.\n\nAdditionally, you may want to detect some information about the current build: build ID, git commit, branch etc.\nFor example, if you'd like to record these values to log, publish them to Slack, etc.\n\n## How\n\nThe detection is based on environment variables injected to the build environment by each CI server.\nHowever, these variables are named differently in each CI. This library contains adapters for many supported\nCI servers to handle these differences, so you can make your scripts (and especially CLI tools) portable to multiple\nbuild environments.\n\n## Supported continuous integration servers\n\nThese CI servers are currently recognized:\n\n - [AppVeyor][appveyor]\n - [AWS CodeBuild][aws-codebuild]\n - [Azure DevOps Pipelines][azure-pipelines]\n - [Bamboo][bamboo]\n - [Bitbucket Pipelines][bitbucket]\n - [Buddy][buddy]\n - [CircleCI][circleci]\n - [Codeship][codeship]\n - continuousphp\n - [drone][drone]\n - [GitHub Actions][github-actions]\n - [GitLab][gitlab]\n - [Jenkins][jenkins]\n - [SourceHut][sourcehut]\n - [TeamCity][teamcity]\n - [Travis CI][travis-ci]\n - Wercker\n\nIf your favorite CI server is missing, feel free to send a pull-request!\n\n## Installation\n\nInstall using [Composer](https://getcomposer.org/):\n\n```sh\n$ composer require ondram/ci-detector\n```\n\n## Example usage\n\n```php\n\u003c?php\n\n$ciDetector = new \\OndraM\\CiDetector\\CiDetector();\n\nif ($ciDetector-\u003eisCiDetected()) { // Make sure we are on CI environment\n    echo 'You are running this script on CI server!';\n    $ci = $ciDetector-\u003edetect(); // Returns class implementing CiInterface or throws CiNotDetectedException\n\n    // Example output when run inside GitHub Actions build:\n    echo $ci-\u003egetCiName(); // \"GitHub Actions\"\n    echo $ci-\u003egetBuildNumber(); // \"33\"\n    echo $ci-\u003egetBranch(); // \"feature/foo-bar\" or empty string if not detected\n\n    // Conditional code for pull request:\n    if ($ci-\u003eisPullRequest()-\u003eyes()) {\n        echo 'This is pull request. The target branch is: ';\n        echo $ci-\u003egetTargetBranch(); // \"main\"\n    }\n\n    // Conditional code for specific CI server:\n    if ($ci-\u003egetCiName() === OndraM\\CiDetector\\CiDetector::CI_GITHUB_ACTIONS) {\n        echo 'This is being built on GitHub Actions';\n    }\n\n    // Describe all detected values in human-readable form:\n    print_r($ci-\u003edescribe());\n    // Array\n    // (\n    //     [ci-name] =\u003e GitHub Actions\n    //     [build-number] =\u003e 33\n    //     [build-url] =\u003e https://github.com/OndraM/ci-detector/commit/abcd/checks\n    //     [commit] =\u003e fad3f7bdbf3515d1e9285b8aa80feeff74507bde\n    //     [branch] =\u003e feature/foo-bar\n    //     [target-branch] =\u003e main\n    //     [repository-name] =\u003e OndraM/ci-detector\n    //     [repository-url] =\u003e https://github.com/OndraM/ci-detector\n    //     [is-pull-request] =\u003e Yes\n    // )\n\n} else {\n    echo 'This script is not run on CI server';\n}\n```\n\n## API methods reference\n\nAvailable methods of `CiInterface` instance (returned from `$ciDetector-\u003edetect()`):\n\n| Method                | Example value                                                                 | Description                                                                                                                                                                                                                                                                                                                                                    |\n|-----------------------|-------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `getCiName()`         | `GitHub Actions`                                                              | Name of the CI server.\u003cbr\u003eThe value is one of `CiDetector::CI_*` constants.                                                                                                                                                                                                                                                                                    |\n| `getBuildNumber()`    | `33`                                                                          | Get number of this concrete build.\u003cbr\u003eBuild 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.    |\n| `getBuildUrl()`       | `https://github.com/OndraM/ci-detector/commit/abcd/checks`\u003cbr\u003eor empty string | Get URL where this build can be found and viewed or empty string if it cannot be determined.                                                                                                                                                                                                                                                                   |\n| `getCommit()`         | `b9173d94(...)`                                                               | Get hash of the git (or other VCS) commit being built.                                                                                                                                                                                                                                                                                                         |\n| `getBranch()`         | `my-feature`\u003cbr\u003eor empty string                                               | Get name of the git (or other VCS) branch which is being built or empty string if it cannot be determined.\u003cbr\u003eUse `getTargetBranch()` to get name of the branch where this branch is targeted.                                                                                                                                                                 |\n| `getTargetBranch()`   | `main`\u003cbr\u003eor empty string                                                     | Get name of the target branch of a pull request or empty string if it cannot be determined.\u003cbr\u003eThis is the base branch to which the pull request is targeted.                                                                                                                                                                                                  |\n| `getRepositoryName()` | `OndraM/ci-detector`\u003cbr\u003eor empty string                                       | Get name of the git (or other VCS) repository which is being built or empty string if it cannot be determined.\u003cbr\u003eThis is usually in form \"user/repository\", for example `OndraM/ci-detector`.                                                                                                                                                                 |\n| `getRepositoryUrl()`  | `https://github.com/OndraM/ci-detector`\u003cbr\u003eor empty string                    | Get URL where the repository which is being built can be found or empty string if it cannot be determined.\u003cbr\u003eThis is either HTTP URL like `https://github.com/OndraM/ci-detector` but may be a git ssh url like `ssh://git@bitbucket.org/OndraM/ci-detector`                                                                                                  |\n| `isPullRequest()`     | `TrinaryLogic` instance                                                       | Detect whether current build is from a pull/merge request.\u003cbr\u003eReturned `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).\u003cbr\u003eUse condition like `if ($ci-\u003eisPullRequest()-\u003eyes()) { /*...*/ }` to use the value. |\n| `describe()`          | `[...]`\u003cbr\u003e(array of values)                                                  | Return key-value map of all detected properties in human-readable form.                                                                                                                                                                                                                                                                                        |\n\n## Supported properties of each CI server\n\nMost CI servers support (✔) detection of all information. However some don't expose\nnecessary environment variables, thus reading some information may be unsupported (❌).\n\n| CI server                          | Constant of `CiDetector` | `is​PullRequest` | `get​Branch` | `get​Target​Branch` | `get​Repository​Name` | `get​Repository​Url` | `get​Build​Url` |\n|------------------------------------|--------------------------|------------------|--------------|---------------------|-----------------------|----------------------|-----------------|\n| [AppVeyor][appveyor]               | `CI_APPVEYOR`            | ✔                | ✔            | ✔                   | ✔                     | ❌                    | ✔               |\n| [AWS CodeBuild][aws-codebuild]     | `CI_AWS_CODEBUILD`       | ✔                | ✔            | ❌                   | ❌                     | ✔                    | ✔               |\n| [Azure Pipelines][azure-pipelines] | `CI_AZURE_PIPELINES`     | ✔                | ✔            | ✔                   | ✔                     | ✔                    | ✔               |\n| [Bamboo][bamboo]                   | `CI_BAMBOO`              | ✔                | ✔            | ✔                   | ✔                     | ✔                    | ✔               |\n| [Bitbucket Pipelines][bitbucket]   | `CI_BITBUCKET_PIPELINES` | ✔                | ✔            | ✔                   | ✔                     | ✔                    | ✔               |\n| [Buddy][buddy]                     | `CI_BUDDY`               | ✔                | ✔            | ✔                   | ✔                     | ✔                    | ✔               |\n| [CircleCI][circleci]               | `CI_CIRCLE`              | ✔                | ✔            | ❌                   | ✔                     | ✔                    | ✔               |\n| [Codeship][codeship]               | `CI_CODESHIP`            | ✔                | ✔            | ❌                   | ✔                     | ❌                    | ✔               |\n| continuousphp                      | `CI_CONTINUOUSPHP`       | ✔                | ✔            | ❌                   | ❌                     | ✔                    | ✔               |\n| [drone][drone]                     | `CI_DRONE`               | ✔                | ✔            | ✔                   | ✔                     | ✔                    | ✔               |\n| [GitHub Actions][github-actions]   | `CI_GITHUB_ACTIONS`      | ✔                | ✔            | ✔                   | ✔                     | ✔                    | ✔               |\n| [GitLab][gitlab]                   | `CI_GITLAB`              | ✔                | ✔            | ✔                   | ✔                     | ✔                    | ✔               |\n| [Jenkins][jenkins]                 | `CI_JENKINS`             | ❌                | ✔            | ❌                   | ❌                     | ✔                    | ✔               |\n| [SourceHut][sourcehut]             | `CI_SOURCEHUT`           | ✔                | ❌            | ❌                   | ❌                     | ❌                    | ✔               |\n| [TeamCity][teamcity]               | `CI_TEAMCITY`            | ❌                | ❌            | ❌                   | ❌                     | ❌                    | ❌               |\n| [Travis CI][travis-ci]             | `CI_TRAVIS`              | ✔                | ✔            | ✔                   | ✔                     | ❌                    | ✔               |\n| Wercker                            | `CI_WERCKER`             | ❌                | ✔            | ❌                   | ✔                     | ❌                    | ✔               |\n\n## Testing\n\nCheck codestyle, static analysis and run unit-tests:\n\n```sh\ncomposer all\n```\n\nTo automatically fix codestyle violations run:\n\n```sh\ncomposer fix\n```\n\n## Standalone CLI version\nIf you want to use CI Detector as a standalone CLI command (ie. without using inside code of PHP project),\nsee [ci-detector-standalone](https://github.com/OndraM/ci-detector-standalone) repository, where you can\ndownload CI Detector as a standalone PHAR file with simple command line interface.\n\n## Changelog\nFor latest changes see [CHANGELOG.md](CHANGELOG.md) file. This project follows [Semantic Versioning](https://semver.org/).\n\n## Similar libraries for other languages\n\nSimilar \"CI Info\" libraries exists for some other languages, for example:\n\n - Go - [KlotzAndrew/ci-info](https://github.com/KlotzAndrew/ci-info)\n - JavaScript/Node.js - [watson/ci-info](https://github.com/watson/ci-info)\n - Python - [mgxd/ci-info](https://github.com/mgxd/ci-info)\n - Rust - [sagiegurari/ci_info](https://github.com/sagiegurari/ci_info)\n\n[appveyor]: https://www.appveyor.com/\n[aws-codebuild]: https://aws.amazon.com/codebuild/\n[azure-pipelines]: https://azure.microsoft.com/en-us/products/devops/pipelines\n[bamboo]: https://www.atlassian.com/software/bamboo\n[bitbucket]: https://bitbucket.org/product/features/pipelines\n[buddy]: https://buddy.works/\n[circleci]: https://circleci.com/\n[codeship]: https://codeship.com/\n[drone]: https://drone.io/\n[github-actions]: https://github.com/features/actions\n[gitlab]: https://about.gitlab.com/solutions/continuous-integration/\n[jenkins]: https://www.jenkins.io/\n[sourcehut]: https://sourcehut.org/\n[teamcity]: https://www.jetbrains.com/teamcity/\n[travis-ci]: https://travis-ci.org/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fondram%2Fci-detector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fondram%2Fci-detector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fondram%2Fci-detector/lists"}