PHP code example of thusithawijethunga / jenkins-laravel-api
1. Go to this page and download the library: Download thusithawijethunga/jenkins-laravel-api library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
thusithawijethunga / jenkins-laravel-api example snippets
php artisan vendor:publish --tag=config
php artisan vendor:publish --provider="JenkinsLaravel\JenkinServiceProvider" --tag="config"
# Url Is Https
JENKINS_URL_HTTPS = false
JENKINS_DOMAIN = host.org
JENKINS_PORT = 8080
JENKINS_USER = admin
JENKINS_TOKEN = token
\config\jenkinapi.php
$jenkins = new \JenkinsLaravel\Jenkins();
https://{jenkins}/user/{user-name}/configure
use JenkinsLaravel\Jenkins as JenkinsApi;
$jenkins = new JenkinsApi();
$jenkins->initialize();
$job = $jenkins->getJob("dev2-pull");
$job->getName();
$job->getFullDisplayName();
$job->getColor();
$job->getIsDisabled();
$job->getNextBuildNumber();
$job->getUrl();
foreach ($job->getHealthReport() as $health) {
$health->iconClassName;
$health->description;
$health->score;
}
$job->getColor(); // blue,red,notbuilt
if($job->getQueueItem())
{
$job->getQueueItem()->getUrl();
$job->getQueueItem()->getInQueueSince();
$job->getQueueItem()->getWhy();
}
foreach ($job->getBuilds() as $build) {
$build->getUrl();
}
if($job->getLastBuild())
{
$job->getLastBuild()->getUrl();
$job->getLastBuild()->getNumber();
}
if($job->getLastCompletedBuild())
{
$job->getLastCompletedBuild()->getUrl();
$job->getLastCompletedBuild()->getNumber();
}
if($job->getLastFailedBuild())
{
$job->getLastFailedBuild()->getUrl();
$job->getLastFailedBuild()->getNumber();
}
if($job->getLastStableBuild())
{
$job->getLastStableBuild()->getUrl();
$job->getLastStableBuild()->getNumber();
}
if($job->getLastSuccessfulBuild())
{
$job->getLastSuccessfulBuild()->getUrl();
$job->getLastSuccessfulBuild()->getNumber();
}
if($job->getLastUnstableBuild())
{
$job->getLastUnstableBuild()->getUrl();
$job->getLastUnstableBuild()->getNumber();
}
if($job->getLastUnsuccessfulBuild())
{
$job->getLastUnsuccessfulBuild()->getUrl();
$job->getLastUnsuccessfulBuild()->getNumber();
}
// is Job Buildable?
$job->getBuildable();
$allJobs = $jenkins->getJobs();
foreach ($allJobs as $job) {
# color
$job->getColor()
# name
$job->getName()
# url
$job->getUrl()
}
$jenkins = new JenkinsApi();
$jenkins->initialize();
$job = $jenkins->launchJob("clone-deploy");
var_dump($job);
// bool(true) if successful or throws a RuntimeException
$jenkins = new JenkinsApi();
$jenkins->initialize();
$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"
$allViews = $jenkins->getViews();
foreach ($allViews as $view) {
# name
$job->getName()
# url
$job->getUrl()
}
$jenkins = new JenkinsApi();
$jenkins->initialize();
$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);
var_dump($jenkins->getJenkinsVersion());
//string(7) "2.361.1";
use JenkinsLaravel\Facade\Jenkin as JenkinsFacade;
# Call initialize function before calling each of other functions
JenkinsFacade::initialize();
$isAvailable = JenkinsFacade::isAvailable();
$jenkinsVersion = JenkinsFacade::getJenkinsVersion();
$allJobs = JenkinsFacade::getJobs();
$allViews = JenkinsFacade::getViews();
bash
curl -sS https://getcomposer.org/installer | php