The reason I created the plugin was because I wanted to integrate Jenkins with an external application. Invoking a Jenkins jobs via the REST API was simple, but getting Jenkins to callback the external application wasn't straight forward.
All the plugins I'd seen either had to be individually configured per job (i.e. in a post build step), or their features were limited to making a HTTP GET/POST request (a bit restrictive).
- I wanted to be able to write my own code
- I didn't want to repeat myself
So I wrote this plugin. Along the way, I realised it could have some other applications too:
- customised logging
- performance monitoring
- incident escalation
- integration with 3rd party applications
- JDK 6 (or above)
To setup for use with Intellij IDEA
To run Jenkins (http://localhost:8080) locally with the plugin installed:
To build the Jenkins plugin (.jpi) file:
To publish/release the Jenkins plugin:
- Update the
gradle.properties, to remove "-SNAPSHOT" (increment and re-add after publishing)
To get started:
- Install the plugin (or run Jenkins locally)
- Navigate to the Jenkins > Manage Jenkins > Configuration page
- You should now see a Global Events Plugin section (similar to the following screenshot).
This plugin executes the supplied Groovy code, every time an event is triggered.
So lets get started with the simplest example.
Now save the changes, kick off a Jenkins job, and you will see "hello world!" written to the logs three times. Alternatively, there's now a
Test Groovy Code button, which will execute the code with the
The plugin actually injects a couple of variables, which you can use in your code. Here's some examples using the
This code limits the logging to only occur when a Job is completed! N.B. this behaviour can also be replicated using the configuration options.
And this one filters on Job's whose name starts with "Foobar"...
There's also a
context Map variable. You can add your own variables to this Map, by returning a Map from your code. E.g.
This will keep a record in memory, of how many times Jobs have finished. You can also achieve the same result, by adding variables directly to the Map variable... e.g.
Not bad! And finally, you can import groovy scripts, so you can hide away some of the heavy lifting... here I'm using a RestClient.groovy script.
You can pretty much do what ever you want from here... custom logging to a file, sending performance metrics to an elastic server, sending email or messenger notifications, calling a SOAP service... the world's your oyster. If you've got something cool that you want to share, let me know and I'll add it to the examples!
For more details on which events trigger the code, what variables are available and details on configuring logging, please see the plugin's help file.
Marky Jackson - firstname.lastname@example.org
Licensed under the MIT License (MIT)