Executing Hudson jobs remotely
I am trying to automate Hudson by hitting the appropriate urls remotely. I am using python's urllib2 for doing the same.
First of all , I am trying to build an existing job and get the build status.
A sample url for the build would look like this:
http://tomcaturl:8080/hudson/job/.NET%20Build/build
However this returns to me html data.
Hudson docs say that I can get data in python/json/xml format, so I try to hit
http://tomcaturl:8080/hudson/job/.NET%20Build/build/api/json
But I get no data at all, although the build happens successfully.
Is there a way to find out which build was started by my remote build request, so that I can maintain a one-to-one mapping.
Plea开发者_高级运维se note that I am doing this through a remote python program and I DO NOT have access to hudson GUI.
First of all, if you have any security/login enabled you have to be logged in to the remote hudson server for the /job/JobName/build. If you allow starting the build without being logged in, this is not a problem.
The /job/JobName/build request will return html data. If you are not logged in you will get a repsonse redirecting to the login page and the build will not be started. If the request is successful you will not get a redirect to the login, and you can assume the build was queued. You can also check the build queue using the api url of the project (see below). Note that there may be a delay before the build is started, which you can control by calling /job/JobName/build?delay=0sec
The API is not available under the job/JobName/build url, but you can see api information here:
http://tomcaturl:8080/hudson/job/.NET%20Build/api
Most pages in hudson that shows information (about a project, a specific build and so on) has an api page if you append /api/xml or /api/json to the end of the url. The reason /job/JobName/build doesn't have an api page is simply because it isn't an url to an information page.
Example api requests:
xml call for information about the project:
http://tomcaturl:8080/hudson/job/.NET%20Build/api/xml
json call for information about the last successful build of the project:
http://tomcaturl:8080/hudson/job/.NET%20Build/lastSucessfulBuild/api/json
精彩评论