phppkg/jenkins-client

Jenkins PHP API client

v1.0.2 2023-11-11 03:03 UTC

This package is auto-updated.

Last update: 2024-05-02 02:45:51 UTC


README

License Php Version GitHub tag (latest SemVer) Unit Tests Deploy Pages

中文说明

jenkins-client - Designed to interact with Jenkins CI using its API.

phppkg/jenkins-client is inspired from the https://github.com/jenkins-khan/jenkins-php-api

Install

  • Required PHP 8.0+

composer

composer require phppkg/jenkins-client

Usage

Before anything, you need to instantiate the client :

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

If your Jenkins needs authentication, you need to pass a URL like this : 'http://user:token@host.org:8080'.

Simple example - sending "String Parameters":

curl JENKINS_URL/job/JOB_NAME/buildWithParameters \
--user USER:TOKEN \
--data id=123 --data verbosity=high

Another example - sending a "File Parameter":

curl JENKINS_URL/job/JOB_NAME/buildWithParameters \
--user USER:PASSWORD \
--form FILE_LOCATION_AS_SET_IN_JENKINS=@PATH_TO_FILE

Here are some examples of how to use it:

Get the color of the job

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

Launch a Job

    $job = $jenkins->launchJob("clone-deploy");
    vdump($job);
    // bool(true) if successful or throws a RuntimeException

List the jobs of a given view

    $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"

List builds and their status

    $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"

Check if Jenkins is available

    var_dump($jenkins->isAvailable());
    //bool(true);

For more information, see the Jenkins API.

License

MIT