Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Jenkins API from AngularJS

I'm trying to retrieve information about one job build from the api rest provided by Jenkins with Angularjs.

Jsonp is actually disabled on Jenkins:

Jenkins Security Advisory 2013-02-16

so this piece of code can't work:

var url = 'http://jenkins-server:8080/job/job-name/api/json?jsonp=callback';
$http.jsonp(url).success(function (data) {
    console.log(data);
});

throw:

Uncaught SyntaxError: Unexpected token : 

Cors is not enabled by default... to be honest I can't find the way to install this plugins:

  • https://github.com/algal/cors
  • https://github.com/jhinrichsen/cors-plugin

and this code can't work as well

var url = 'http://jenkins-server:8080/job/job-name/api/json'
$http({url: url, method: 'GET'}).success(function(data){console.log(data)})
like image 596
Mauro Avatar asked Oct 24 '13 16:10

Mauro


2 Answers

You can use this CORS filter plugin:

https://wiki.jenkins-ci.org/display/JENKINS/Cors+Filter+Plugin

Or you can host your Angular app on the Jenkins server using the User Content mechanism:

https://wiki.jenkins-ci.org/display/JENKINS/User+Content

like image 173
afternoon Avatar answered Oct 03 '22 18:10

afternoon


There seems to be a plugin now for whitelisting JSON requests...Just go to the plugins, and search for JSON.

The Secure Access plugin.

like image 28
Tony K. Avatar answered Oct 03 '22 19:10

Tony K.