Server Sent Events (SSE) Gateway plugin for Jenkins.
Uses the pubsub-light-module jenkins-module to receive light-weight events and forward them into browser-land via SSE.
npm install --save @jenkins-cd/sse-gateway
This plugin requires Jenkins version 2.2 or later.
2.2+ is needed because it supports Servlet 3 asynchronous requests, which are needed for Server Sent Events.
The API is quite simple, allowing you to
subscribe to (and
unsubscribe from) Jenkins event
The "job" channel is where you listen for events relating to Jenkins Jobs, all of which are enumerated in the Events.JobChannel Javadoc.
var sse = ;// Connect to the SSE Gateway, providing an optional client Id.var connection = sse;// subscribe to all events on the "job" channel...var jobSubs = connection;// And some time later, unsubscribe using the return from the subscribe...connection;
The above example subscribes to all events on the "job" channel i.e. all events for all jobs in the Jenkins instance. This may be what you want in some cases, but in many cases you are just interested in receiving specific events. To do this, you simply need to specify a "filter" when subscribing to the channel.
For example, to only receive "FAILURE" events for the "order-management-webapp-deploy" job:
var sse = ;// Connect to the SSE Gateway, providing an optional client Id.var connection = sse;// Add a filter as the last parameter ...var jobSubs = connection;// And some time later, unsubscribe using the return from the subscribe...connection;
As is to be expected, the connection to Jenkins can be lost. To handle this situation, simply register an
onError handler with the connection instance.
var sse = ;// Connect to the SSE Gateway.var connection = sse;// Connection error handling...connection;// etc...
Note that only one handler can be registered per
Note how the supplied
connection.onError handler makes a call to
connection.waitConnectionOk takes a connection status callback handler. This handler is called
periodically until the connection is ok again i.e. it can be called more than once, constantly getting
feedback on the connection state.
As always with Internet Explorer, there are issues. It doesn't support the SSE
EventSource so in order to
use it on Internet Explorer, please make sure that a polyfill is added to the page before your app. We have
used this one and found it to work fine.
To add this polyfill to your
.jelly file, simply include the following adjunct as early as possible.
var sse = ;// etc....
The SSE Gateway client code uses the
@jenkins-cd/logging package for client-side/browser logging. See the Browser Configuration docs for how to configure logging in your browser, configuring the stored value of
jenkins-instance/logging/categories:org.jenkinsci.sse for SSE logs.
See the sse-gateway-sample-plugin.