One of the Ruby-specific Stapler extension is to delegate the HTTP request dispatching process completely to a Rack application. This allows your plugin to define a subtree of the URL space by using a familiar Ruby-based web framework, such as Sinatra and Ruby on Rails.
To do this, simply include Jenkins::RackSupport
to your model class, then implement the call method that follows the Rack specification. Most typically, you'll simply delegate to a Rack application created elsewhere. The following example shows an implementation of RootAction that uses a sinatra app to define its URL subspace. In this case, an instance of TestRootAction
is bound to /root_action
, so /root_action/hi
would be processed by this Sinatra app to say hello world.
require 'sinatra/base' require 'jenkins/rack' class SomeSinatraApp < Sinatra::Base get '/hi' do 'Hello world from Sinatra!' end end class TestRootAction < Jenkins::Actions::RootAction include Jenkins::RackSupport def call(env) SomeSinatraApp.new.call(env) end display_name "Test Root Action" def icon "gear.png" end def url_name "root_action" end end