mcampbell508/ci-detector

此包已被废弃且不再维护。未建议替代包。

检测当前持续集成服务器并提供对当前构建属性的统一访问

3.2.0 2018-08-07 13:22 UTC

This package is auto-updated.

Last update: 2023-06-27 22:44:54 UTC


README

Latest Stable Version Travis Build Status AppVeyor Build Status License

一个简单的PHP库,用于检测当前脚本正在运行的持续集成服务器,并提供访问构建属性的统一接口。

检测基于每个持续集成服务器注入到构建环境中的环境变量。然而,这些变量在每个CI中命名不同。此库包含每个支持CI服务器的适配器,以处理这些差异,因此您不需要,可以使您的脚本(尤其是CLI工具)适用于多个构建环境。

支持的持续集成服务器

这些CI服务器目前被识别

如果您的 favorite CI 服务器缺失,请随时发送 pull-request!

独立CLI版本

如果您想将 CI Detector 作为独立的 CLI 命令使用(即,不使用在 PHP 项目的代码中),请参阅 ci-detector-standalone 存储库,您可以从那里下载带有简单命令行界面的独立PHAR文件。

安装

使用 Composer 安装

$ composer require ondram/ci-detector

Ci-detector 需要 PHP 7.1+,但如果您需要与 PHP <7.1 兼容,您仍然可以使用旧版本的 ci-detector 2.x。

示例使用

<?php

$ciDetector = new \OndraM\CiDetector\CiDetector();

if ($ciDetector->isCiDetected()) {  // Make sure we are on CI environment
    $ci = $ciDetector->detect();    // Returns class implementing CiInterface or throws CiNotDetectedException

    // Example output when run in Travis:
    echo $ci->getCiName();          // "Travis CI"
    echo $ci->getBuildNumber();     // "35.1"
    echo $ci->getBuildUrl();        // "https://travis-ci.org/OndraM/ci-detector/jobs/148395137"
    echo $ci->getGitCommit();       // "fad3f7bdbf3515d1e9285b8aa80feeff74507bdd"
    echo $ci->getGitBranch();       // "feature/foo-bar"
    echo $ci->getRepositoryUrl();   // "" (empty string) - unsupported on Travis, will return eg. "ssh://git@gitserver:7999/project/repo.git" on Jenkins etc.)
} else {
    echo "CI not detected";
}

测试

运行单元测试

vendor/bin/phpunit

检查代码风格

vendor/bin/php-cs-fixer fix --diff --dry-run # remove the --dry-run option to fix the codestyle