This composer library is designed to facilitate interactions with Jenkins CI using its API or CLI via SSH.
This library is distributed with the MIT License applied to all work within.
Note: This is a fork of the original repository created by Jenkins Khan, located here. A huge thanks to them for starting this project.
The primary focus of this fork is to facilitate additional functionality through the Jenkins CLI via. SSH. Since many publicly-accessible pieces of functionality are changing from the original, this fork is also published as it's own Composer package under my identity (ooobii).
To begin utilizing Jenkins Management for PHP, you can install it using 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
If you do not have Composer installed, you can download the binary to your project's folder:
# Always exercise caution when executing installer scripts from remote sources!
curl -sS https://getcomposer.org/installer | php
# This isn't required, but it's easier to refer to it this way.
mv composer.phar composer
Alternatively, you can install it on your system globally, so the command composer
will be accessible anywhere:
# Always exercise caution when executing installer scripts from remote sources!
wget "https://getcomposer.org/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
Before anything, you need to instantiate the client:
$jenkins = new \ooobii\Jenkins($host, $port = NULL, $useHttps = TRUE, $user = NULL, $token = NULL);
OR:
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"
var_dump($jenkins->isAvailable());
//bool(true);
For more information, see the Jenkins API.