PHP code example of phppkg / jenkins-client

1. Go to this page and download the library: Download phppkg/jenkins-client 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/ */

    

phppkg / jenkins-client example snippets


$jenkins = new \PhpPkg\JenkinsClient\Jenkins('http://host.org:8080');

    $job = $jenkins->getJob("dev2-pull");
    vdump($job->getColor());
    //string(4) "blue"

    $job = $jenkins->launchJob("clone-deploy");
    vdump($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);