Due to some maintenance issues, this service has been switched in read-only mode, you can find more information about the why

and how to migrate your plugin documentation in this blogpost

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

One of many ways to handle an HTTP request is by writing a method on your URL-bound classes. In Stapler-speak, these methods are called "web methods".

Web methods are public instance methods that has the name that starts with "do", for example:

class MyRootAction {

  public HttpResponse doStart() {
    return HttpResponses.redirectTo(".");

Such a method would handle an HTTP request sent to /.../start (again, see the reference for the exact routing rules)


Web methods can define parameters. When Stapler invokes your web method, it needs your help to figure out what you expect in those parameters, and there are several ways to do this.

Firstly, if the type of a parameter is one of the following "well-recognized" types, Stapler would instantly know what to do:

  • StaplerRequest/HttpServletRequest — the request object
  • StaplerResponse/HttpServletResponse — the response object

Secondly, you can place parameter injection annotations to instruct Jenkins what you want to see in that parameter. Unlike typical Java programming, parameter names are significant.

  • @Header: requests that the value of the request HTTP header be injected.
    public HttpResponse doStart(@Header String referer) { ... }
  • @QueryParameter: requests that the value of the request parameter be injected. This includes a submitted form and a query parameter.
  • @AncestorInPath: Stapler will call StaplerRequest.findAncestor(Class) and inject the obtained object. This object is the nearest "ancestor" of the specified type in the current URL.

(One can define a custom injection parameter by using the @InjectedParameter meta annotation, which is how all these annotations are defined.)

The type of the injected parameter can be anything, and Apache Commons Beanutils is used to convert the incoming value into the appropriate Java type your method requests.


Return value and exception


  • No labels