Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Hudson-ci/help/remote access api

< Hudson-ci
Revision as of 03:02, 2 March 2013 by Duncan.r.mills.gmail.com (Talk | contribs) (Submitting jobs)

Hudson Continuous Integration Server
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug Day
Contribute
Browse Source
Hudson-bust.png Help - Remote Access API












Summary

Hudson provides machine-consumable remote access API to its functionalities. It comes in two built-in flavors, with an additional alternative REST module as a separate plugin:

  1. XML
  2. JSON with JSONP support

Remote access API is offered in a REST-like style. That is, there is no single entry point for all features, and instead they are available under the ".../api/" URL where "..." portion is the data that it acts on.

For example, if your Hudson installation sits at http://deadlock.netbeans.org/hudson/, http://deadlock.netbeans.org/hudson/api/ will give you HTML lists of all available functionalities that act on the Hudson root. For example, from here you can access all the jobs on Hudson via XML/JSON. Or if you want to access information about a particular build at http://deadlock.netbeans.org/hudson/job/trunk/lastSuccessfulBuild/, then go to http://deadlock.netbeans.org/hudson/job/trunk/lastSuccessfulBuild/api/ and you'll see the list of functionalities for the build.

What can you do with it?

Remote API can be used to do things like these:

  1. Retrieve information from Hudson for programmatic consumption.
  2. Trigger a new build
  3. Create/copy jobs

Submitting jobs

For a job with no parameters, you need merely go an HTTP GET on:

{{{1}}}

{{{1}}}

where TOKEN is set up in the job configuration.

If you have parameters, you need to send JSON. Here's a snipped of shell, with a few extra newlines to be more readable.

{{{1}}}

Remote API and Security

When your Hudson is secured, you can use HTTP BASIC authentication to authenticate remote API requests. See Authenticating scripted clients for more details.

Sample code

A simple client is available to demonstrate how you can invoke the XML from Java. Here's the code:


Unsecured Server Version


Secured Server Version



Using XPath

XPath selection

The XML API supports a selection by XPath by using the query parameter 'xpath'. This is convenient for extracting information in environments where XML manipulation is tedious (such as shell script.) See issue #626 for an example of how to use this. See .../api/ on your Hudson server for more up-to-date details.

XPath exclusion Similar to the 'xpath' query parameter above, you can use (possibly multiple) 'exclude' query patterns to exclude nodes from the resulting XML. All the nodes that match the specified XPath will be removed from the XML. See .../api/ on your Hudson server for more up-to-date details.

Depth control Sometimes the remote API doesn't give you enough information in one call. For example, if you'd like to find out all the last successful build of a given view, you'd realize that the invocation to the remote API of the view won't give you this, and you'd have to recursively call the remote API of each project to find this out. The depth control, introduced in 1.167, solves this problem. To understand this feature, it's good to start with how the remote API works.

The data model that Hudson maintains internally can be thought of as a big tree structure, and when you make a remote API call, you are getting a small subtree of it. The subtree is rooted at the object for which you made a remote API call, and the sub-tree is cut beyond certain depth to avoid returning too much data. You can adjust this cut-off behavior by specifying the depth query parameter. When you specify a positive depth value, the subtree cut-off happens that much later.

So the net result is, if you specify a bigger depth value, you'll see that the remote API will now return more data. Because of the algorithm, this works in such a way that the data returned by a bigger depth value includes all the data returned by smaller depth value.

See .../api/ on your Hudson server for more up-to-date details.

Detecting Hudson version To check the version of Hudson, load the top page and check for the "X-Hudson" response header. This contains the version number of Hudson, like "1.358" This is also a good way to check if an URL is a Hudson URL.

Discovering Hudson on the network Hudson instances listen on UDP port 33848. Whenever a UDP packet is received, it will respond with a short XML fragment that shows the connection information. This XML has the following format:

<hudson>

 <version>1.380</version>           
<url>http://somwhere/hudson/</url> 
<slave-port>12345</slave-port>     

</hudson> By using this, a client can use a UDP broadcast to try to discover nearby Hudson instances. This is primarily useful for a self-organizing build cluster.

Back to the top