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:
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)})
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
There seems to be a plugin now for whitelisting JSON requests...Just go to the plugins, and search for JSON.
The Secure Access plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With