Create a Plugin

After preparing your environment, the next step is to create a new plugin.

If your intention is to publish your plugin on the Jenkins update site, now is a good time to look for plugins that already do something similar. See this wiki page for more information.

Create the Project Layout with Sample Plugin Archetype

Open a command prompt, navigate to the directory you want to store your new Jenkins plugin in, and run the following command:

mvn -U archetype:generate -Dfilter=io.jenkins.archetypes:

This command will let you generate one of several project archetypes related to Jenkins. In this tutorial we’re going to use the hello-world archetype, version 1.3, so select that:

$ mvn -U archetype:generate -Dfilter=io.jenkins.archetypes:
Choose archetype:
1: remote -> io.jenkins.archetypes:empty-plugin (Skeleton of a Jenkins plugin with a POM and an empty source tree.)
2: remote -> io.jenkins.archetypes:global-configuration-plugin (Skeleton of a Jenkins plugin with a POM and an example piece of global configuration.)
3: remote -> io.jenkins.archetypes:hello-world-plugin (Skeleton of a Jenkins plugin with a POM and an example build step.)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 3 (1)
Choose io.jenkins.archetypes:hello-world-plugin version:
1: 1.1
2: 1.2
3: 1.3
Choose a number: 3: 3 (2)
[INFO] Using property: groupId = unused
Define value for property artifactId: demo (3)
Define value for property version 1.0-SNAPSHOT: : (4)
[INFO] Using property: package = io.jenkins.plugins.sample
Confirm properties configuration:
groupId: unused
artifactId: demo
version: 1.0-SNAPSHOT
package: io.jenkins.plugins.sample
 Y: : y (5)
1 Enter the number for the hello-world-plugin archetype, 3 in this case.
2 This tutorial is based on version 1.3 of the hello-world-plugin archetype, so enter 3 to select it.
3 This is mandatory and uniquely identifies your plugin in Jenkins. This plugin tutorial uses the name demo (user input highlighted in bold). If you want to publish your plugin, make sure the name is not already taken, and that the name you choose is future-proof: the artifactId cannot be changed after you’ve published your first release. Do not use the words jenkins or plugin in this ID—only the words describing what kind of Jenkins plugin this is.
4 There’s no need to choose a different version number here. This is the development version (indicated by SNAPSHOT) of version 1.0. Learn more about Maven version numbers.
5 After you enter all the values, Maven will show them again. Review and confirm your selection.

This creates a directory with the same name as the plugin’s artifactId (demo in this case), and adds the basic structure for a working plugin. Let’s make sure we can build the plugin:

$ mv demo demo-plugin (1)
$ cd demo-plugin
$ mvn verify
1 Maven has created the project structure in a directory with the same name as you chose for your plugin. We will rename the directory to match the conventional repository names used in the GitHub organization @jenkinsci.

Maven will download several more dependencies, and then go through the configured build lifecycle, including static analysis (FindBugs) and tests, until it shows something like this:

[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 06:11 min
[INFO] Finished at: 2017-03-02T14:14:34+01:00
[INFO] Final Memory: 73M/872M
[INFO] ------------------------------------------------------------------------
To learn more about what’s involved in a plugin build, see Plugin Build Process.

Not the output you’re seeing? See the Troubleshooting section below.

Let’s run the plugin and see what it does.


Anything not working for you? Ask for help in chat or on the jenkinsci-dev mailing list.