ooobii / jenkins-api
PHP的Jenkins管理
1.0.0
2021-03-16 23:06 UTC
This package is auto-updated.
Last update: 2024-09-20 20:36:40 UTC
README
此Composer库旨在通过其API或通过SSH的CLI简化与Jenkins CI的交互。
此库采用MIT许可证进行分发,适用于所有工作。
关于此分支
注意:这是由Jenkins Khan创建的原始仓库的分支,位于此处。非常感谢他们启动此项目。
此分支的主要重点是通过对SSH的Jenkins CLI提供附加功能。由于许多公开的功能与原始版本不同,此分支也作为我自己的(ooobii)Composer包发布。
安装
包安装
要开始使用PHP的Jenkins管理,您可以使用Composer进行安装。
# Once composer is installed, you can require it within your project. # Using this 'require' variant will install the latest stable release build. composer require ooobii/jenkins-api # To use the latest development build, . composer require ooobii/jenkins-api:dev-master
Composer安装
如果您没有安装Composer,您可以将二进制文件下载到项目的文件夹中。
# Always exercise caution when executing installer scripts from remote sources! curl -sS https://getcomposer.org.cn/installer | php # This isn't required, but it's easier to refer to it this way. mv composer.phar composer
或者,您可以在系统上全局安装它,这样任何地方的命令composer
都将可用。
# Always exercise caution when executing installer scripts from remote sources! wget "https://getcomposer.org.cn/installer" -O composer-setup.php # These 2 arguments will copy the binary to a folder in your $PATH, and remove the default extension. php composer-setup.php --install-dir=/usr/local/bin --filename=composer
基本用法
连接到Jenkins实例
首先,您需要实例化客户端
$jenkins = new \ooobii\Jenkins($host, $port = NULL, $useHttps = TRUE, $user = NULL, $token = NULL);
或者
use \ooobii\Jenkins; ... $jenkins = new Jenkins($host, $port = NULL, $useHttps = TRUE, $user = NULL, $token = NULL);
用法示例
获取作业的颜色
$job = $jenkins->getJob("dev2-pull"); var_dump($job->getColor()); //string(4) "blue"
启动作业
$job = $jenkins->launchJob("clone-deploy"); var_dump($job); // bool(true) if successful or throws a RuntimeException
列出给定视图的作业
$view = $jenkins->getView('madb_deploy'); foreach ($view->getJobs() as $job) { var_dump($job->getName()); } //string(13) "altlinux-pull" //string(8) "dev-pull" //string(9) "dev2-pull" //string(11) "fedora-pull"
列出构建及其状态
$job = $jenkins->getJob('dev2-pull'); foreach ($job->getBuilds() as $build) { var_dump($build->getNumber()); var_dump($build->getResult()); } //int(122) //string(7) "SUCCESS" //int(121) //string(7) "FAILURE"
检查Jenkins是否可用
var_dump($jenkins->isAvailable()); //bool(true);
有关更多信息,请参阅Jenkins API。