There are a lot of existing Jenkins plugins, and plugins and a lot of people with Jenkins plugin development experience that you can take advantage of!
Jenkins defines extensibility points, which are interfaces or abstract classes that model an aspect of a build system. Those interfaces define contracts of what need needs to be implemented, and Jenkins allows plugins to contribute those implementations. See this document for more about extension points.
You are advised to use the NetBeans plugin for Jenkins/Stapler development. This offers many Jenkins-specific features. Most visibly, create a new plugin using New Project » Maven » Jenkins Plugin, and use Run rojectproject to test it.
IntelliJ 7.0 (or later) users can load pom.xml directly from IDE, and you should see all the source code of libraries and Jenkins core all the way to the bottom. Consider installing the IntelliJ IDEA plugin for Stapler to make the development easier.
Alternatively,emtpy create a new Maven project using Create from archetype and Add an Archetype. Select the GroupId and ArtifactId as above and choose RELEASE as version. In the next screen select io.jenkins.plugins as groupID and choose an artifactId (Project name) and Version to your liking. This will automatically create a maven project based on the specified artifact (e.g. emtpyempty-plugin).
IntelliJ defaults to downloading sources and JavaDocs on demand. So, to see the source, you may need to click the
As Jenkins plugins are Maven projects, Eclipse users have two ways to load a Jenkins plugin project. One is to use m2e, which tries to make Eclipse understand Maven "natively", and the other is to use theusing maven, but Maven Eclipse plugin, which makes Maven generate Eclipse project definitions. At the moment, unless you have some prior experience with m2e, we currently recommend plugin developers to go with the Maven Eclipse plugin.
See Eclipse alternative build setup for an alternative way of setting up the Eclipse build environment, that is a bit more technically involved than using maven, Maven but can give faster build times.
The bulk of work in the plugin consists in of implementing those extension points. See the sample source code for more information about how a
Builder is implemented and what it does.
Here are a few things about extension:
- in general, a plugin extension should extend an existing extension point (a class that implements ExtensionPoint), and define an inner static class extending the corresponding descriptor (a class extending hudson.model.Descriptor)
- the @Extension annotation must be placed on the inner descriptor class to let Jenkins know about this extension
- the descriptor handles the global configuration of the extension while the extension class itself handles the individual configuration of the extension. For instance, the Setting context path
in a plugin defining a class extending LabelAtomProperty, an object of this class is instantiated for each LabelAtom (provided that the plugin is activated by the user in the label's configuration page). If configuration parameters for each individual instance are required, they're handled via a config.jelly file stored in a resource package named after the extension class. When the configuration form is saved, Jenkins calls the extension constructor marked with the @org.kohsuke.stapler.DataBoundConstructor annotation, matching parameters by name
maven-hpi-plugin 1.65 or later (used by parent POM 1.401 or later) can set the context path by using a system property. On more recent versions of Jenkins, the "/jenkins" prefix is added automatically.
- Views: Groovy/Jelly views are re-compiled every time a browser requests a page, so just reload a page in the browser and you'll see the changes. This is also true for help files you write.
- Java code: If you are debugging, JVM's hot swap feature can be used to reload code so long as you do not touch the method signature. (For example, from NetBeans use Debug » Apply Code Changes.) Beyond that, you can hit ENTER in the Maven process and it'll reload the Jenkins webapp, though generally, it is better to stop the process and start again. See Developing with JRebel for how to get a JRebel license for OSS projects to improve this experience.
- POM: If you change POM, you'll have to stop and restart Maven to see the changes.
- Consider running Maven like this
mvn -o ...to avoid hitting repositories every time. This will make various operations considerably faster.
- Subscribe to the users' alias from here so that we can get in touch with you.
- When you bump up the version of Jenkins you depend on, make sure to run
mvn cleanonce, in particular, to delete
target/workthat Jetty uses. Newer versions may just use work, not target/work. Otherwise, your Jetty may continue to pick up old left-over JAR files.
- If you have a high latency network connection to the Maven repository, you might find it faster to first run the build once on a server near to the maven repository, then rsync the .m2/repository folder across to your local computer
- The 'package' and 'install' targets will by default run many tests. You can add '-DskipTests' on the command-line to skip these (of course you should run the tests before committing any changes)
- The 'compiler:compile' goal is faster than 'compile', because it is a goal, rather than a lifecycle event, and therefore avoids certain earlier goals, such as setting up resources
Besides this tutorial, there are other tutorials and examples available on lineonline:
- Making your plugin compatible with Pipeline
- Stephen Connolly's 7 part tutorial (Writing a Hudson plugin)
- Part 1 - Preparation
- Part 2 - Understanding m2 and freestyle projects
- Part 3 - Subcontracting for Publisher and MavenReporter
- Part 4 - Abstract Publishers and MavenReporters
- Part 5 - Reporting
- Part 5½ - Typos corrected
- Part 6 - Parsing the results
- Part 7 - Putting it all together
- yet not finished: health reports
- Quick start guide in Japanese
- ~martino:/2011/10/27/The JenkinsPluginTotallySimpleGuide by martinO
- Implementing My First Jenkins Plugin: AnsiColor by Daniel Doubrovkine
- Tutorial: Create a Jenkins Plugin to integrate Jenkins and Nexus Repository by Marcel Birkner