Writing Programs that Drive Jenkins


This is something I always believed in — that every piece of software needs to be usable but a layer above. Or put another way, every software should be usable as a library.

Let’s start with the REST API of Jenkins. For most of the data Jenkins renders as HTML, you can access its XML version and JSON version (as well as a few other formats, like Python literal fragment.) You do this by adding /api to the page (see http://ci.jenkins-ci.org/api for example.) Those pages discusss other REST API where applicable. For example, you can POST to a certain URL and it’ll create/update job definitions, etc.





A slightly different version of the CLI is “Jenkins as SSH server”. Jenkins speaks the server side of the SSH protocol, and allows regular SSH clients to execute a subset of CLI commands. In this way, you don’t need a Java runtime installed on the client side to drive Jenkins.



One is the REST API access to the Groovy console, which allows administrator users to run arbitrary Groovy scripts inside the Jenkins master JVM (and you can submit this script as POST payload, and get the response back as the HTTP response). This allows you to tap into all the Jenkins object models. Unlike the REST API, in this way you can ship the computation, so in one round-trip you can do a lot. You can do the same with CLI, which also lets you access stdin/stdout of the CLI.
The other sophisticated integration API I wanted to talk about is the remoting API that does Java RPC (not to be confused with the remote API, which is the synonym for the REST API). The remoting API is the underlying protocol that we use for master/slave communications, and it revolves around the notion of shipping a closure (and code associated with it) from one JVM to another, executing it, and getting the result back. If your application runs elsewhere, you can establish the remoting API channel with Jenkins master, then prepare a Callable object. You can then have Jenkins master execute this closure, and the result is sent back to your JVM.



I think this list covers all the major integration APIs that Jenkins offers. If you are building any interesting applications that use Jenkins as a building block, please share your experience so that we can make it better!

Kohsuke Kawaguchi
Jenkins Founder, Elite Developer & Architect

Blog Categories: 


This comment has been removed by the author.

Add new comment