GithubHelp home page GithubHelp logo

jenkins-php-api's Introduction

Jenkins Khan

Jenkins Khan is a php tool that helps you manage a Jenkins integration server.

With JK you can easily launch different jobs on your working branches and check the result of each job, grouped by your branches.

Why ?

When it comes to working with many branches, Jenkins is not very user-friendly.
It's kind of a mess to check your jobs state on every branch. We need an overview.

How ?

Jenkins Khan uses Jenkins' API to retrieve the configuration, jobs, jobs parameters, view, status, etc.
You just have to register your Jenkins Url in Jenkins Khan and enjoy the fun.

Requirements

  • Jenkins
  • Jenkins Git Plugin (but it should work on any VCS you want)
  • Each Jenkins job must have a branch specifier named BRANCH
  • PHP >= 5.2

jenkins-php-api's People

Contributors

agallou avatar elliotwms avatar ianfixes avatar kuikui avatar nickdaugherty avatar s-larionov avatar srogier avatar timcrider avatar xebuz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jenkins-php-api's Issues

Not able to use the api

Hi,
I was trying to use the api in my php code to see if I can get the jenkins data and display it on a page.
I wrote a sample script, but I do not see anything happening. I have installed the package on my local system using "php composer.phar require jenkins-khan/jenkins-api=dev-master"

Then used the below script:

:@test-jenkins.internal.xyzcomp.com:8443'); $view = $jenkins->getView('TestView'); foreach ($view->getJobs() as $job) { var_dump($job->getName()); } ?>

Can you please help me fix the problem

More debug info

Consider adding this to the curl exception messages to help with troubleshooting curl issues:

sprintf('Error during getting information for view %s on %s: %s', $viewName, $this->baseUrl, curl_error($curl))

for example on getting view jobs

Crumbs should be enabled by default

All modern Jenkins version ship with CSRF protection enabled out-of-the-box, so this library should enable crumbs by default to deal with that.

HTTP abstraction

Need to move away from hardcoded cURL functions and use something like Guzzle as a HTTP layer. This will make managing #35 much easier.

The deleteJob function ain't work well

My env.
system: centos 7
jenkins ver.1.612
php5.6.*
curl(system) ver.7.29.0
using nginx

I don't know what's wrong with jenkins or curl. It seems that one of them can't recognize the POST method unless I send a empty array POSTFIELDS with it.

public function deleteJob($jobName){
  /*
    ******
  */
  curl_setopt($curl, \CURLOPT_POST, 1);
  curl_setopt($curl, \CURLOPT_POSTFIELDS, []); // the deff line
  /*
    ******
  */
}

No way to handle workspace paths for the job names

Some jenkins jobs are setup within a workspace, and as such the path to that job may be something like

    http://host.com/jenkinspath/work/space/path/jobname

This tool doesn't account for the workspace. For launching the job I was able to simply pass work/space/path/jobname as the value for the jobname. However when using other methods like getJob(), for example, the tool tries to grab the job name from the api response instead of the one provided by the developer. This doesn't include the workspace, and so this failed.

I patched this up for my own purposes in my fork, here cdc95e0. This is a quick and dirty solution, which only addresses my immediate need. My solution was to

  • change the return statement of a couple methods, including the getJob() method so that it passes the $jobname it already has as a parameter.
  • change the Jenkins_Job constructor to receive this variable.
  • change the Jenkins_Job->getName() method to use that variable.

The work I did was quick and messy, and not thought out. I don't recommend merging it into your code, hopefully its a starting point to help solve the problem.

Thanks for making this to begin with, it saved me a lot of time.

More graceful handling of non existent jobs in Jenkins::getJob()

Jenkins::getJob() doesn't properly handle a 404 from Jenkins - it attempt so run json_decode on any non-cURL error response, which includes 404s, so a non-existent job results in this exception being thrown:

throw new RuntimeException('Error during json_decode');

This is not reliable for determining if a job exists or not, as we can't distinguish between this condition and a real json error.

A better approach would be to return false when Jenkins returns a 404.

garbled code in job setting - when create and set

Sending configures in xml. I keep xml file in UTF8 encoding as usual. But seems that Jenkins refuse to decode xml in UTF8 without the header charset below.

public function createJob($jobname, $xmlConfiguration)
{
  /*
    ******
  */

  $headers = array('Content-Type: text/xml;charset=utf-8'); //Add encoding charset to header

  /*
    ******
  */
}

public function setJobConfig($jobname, $configuration)
{
  /*
    ******
  */

  $headers = array('Content-Type: text/xml;charset=utf-8'); //Add encoding charset to header

  /*
    ******
  */
}

add method executeJob($name)

i not found method for create job, use:
$jenkins->execute("job/$name/build", [
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => [
$jenkins->getCrumbHeader(),
]
]);

Composer install failed

Running composer require jenkins-khan/jenkins-api shows this error:

[InvalidArgumentException]
Could not find package jenkins-khan/jenkins-api at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.