php 调用jenkins 接口,jenkins-php-api

Jenkins PHP API

Jenkins PHP API is a set of classes designed to interact with Jenkins CI using its API.

Installation

The recommended way to install Jenkins PHP API is through Composer.

curl -sS https://getcomposer.org/installer | php

Then, run the Composer command to install the latest version:

composer.phar require jenkins-khan/jenkins-api

Basic Usage

Before anything, you need to instantiate the client :

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

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

Here are some examples of how to use it:

Get the color of the job

$job = $jenkins->getJob("dev2-pull");

var_dump($job->getColor());

//string(4) "blue"

Launch a Job

$job = $jenkins->launchJob("clone-deploy");

var_dump($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.

Coding standards

This projects follows PSR-0, PSR-1, PSR-2, PSR-4

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值