jenkins-khan / jenkins-php-api Goto Github PK
View Code? Open in Web Editor NEWPHP API for Jenkins
PHP API for Jenkins
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
/*
******
*/
}
Need to move away from hardcoded cURL functions and use something like Guzzle as a HTTP layer. This will make managing #35 much easier.
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.
Avec un petit exemple d'utilisation ?
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
/*
******
*/
}
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
getJob()
method so that it passes the $jobname
it already has as a parameter.Jenkins_Job
constructor to receive this variable.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.
i not found method for create job, use:
$jenkins->execute("job/$name/build", [
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => [
$jenkins->getCrumbHeader(),
]
]);
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.
On completed jobs, Jenkins_Build::getRemainingExecutionTime()
will return a negative number due to how the value is calculated.
This should have a lower bounds of 0
.
Would be tremendously useful to have the build number at least when launching instead of just a boolean.
The capitalizations RuntimeException
and RunTimeException
are both used, should standardize on RuntimeException
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
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
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
Really?
The library should support retrieving and using anti-csrf crumbs.
https://wiki.jenkins-ci.org/display/JENKINS/Securing+Jenkins
can you please provide the API to create View for Pipeline view?
Could you please specify a License type for this project?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.