It has long been possible to build Jenkins plugins using Maven, but now you can build and release your Java and Groovy plugins using Gradle.
- Gradle 2.8
- Your plugin must be built against a Jenkins core version of 1.420 or later, due to the Gradle plugin relying on changes which were made to the annotation handling around that time.
Once you've got Gradle installed, create your plugin project. The plugin project's directory should be named "foo-plugin" or "foo", where "foo" is the artifact name for the plugin. In the build.gradle for the plugin, place the following at the top:
Make sure any additional repositories you need are defined after the
jenkinsPlugin section, or artifact resolution may take a long time.
To build, run
gradle jpi. This will create a
.hpi file in the
build/libs directory in your plugin project directory.
To run all unit tests, run
gradle test. Unlike with Maven, the tests will not be automatically run when building the plugin via
gradle jpi, or when releasing via
To spin up a Jenkins instance with this plugin installed for manual testing, run
gradle server. The Jenkins instance will be available on port 8080 on your localhost. The HTTP port can be changed with the
jenkins.httpPort project or system property, e.g.
gradle server -Djenkins.httpPort=8082.
To deploy your plugin to your local Maven repository, run
It is possible to attach a remote debugger to the Jenkins instance started by
gradle server. The
GRADLE_OPTS environment variable must be used to configure the JVM debug options.
The Gradle JPI plugin does not provide an automated release with Gradle, so you will need to make sure your version is not a SNAPSHOT version manually. It is recommended that you check in your
build.gradle file with your release version, tag it with
foo is your plugin's name, and
0.0.1 is your release version. You should then push that tag to GitHub.
Once you have updated the version and tagged the tree, you can release by running
gradle clean publish. This will build the plugin and deploy it to the Jenkins Maven repository for inclusion in the update center. The Gradle JPI plugin will look for your Jenkins Maven repository credentials in the file
~/.jenkins-ci.org where it expects to find:
Dependencies on other Jenkins Plugins
If your plugin depends on other Jenkins plugins you can specify the dependencies in the following way:
Adding the dependency to the
jenkinsPlugins configuration will make all classes available during compilation and also add the dependency to the manifest of your plugin. To define an optional dependency on a plugin then use the
optionalJenkinsPlugins configuration and to use a plugin only for testing, add a dependency to the
Note that you must use the artifact only notation (append
@jar if you're using the semicolon notation as in the example or specify
ext: 'jar' if you're using the map-style notation).
- The Job DSL plugin is built with Gradle.
- You can also clone the Hello World plugin and copy in the example build.gradle from the gradle-jpi-plugin's doc directory, and build it.
- simple-scm-plugin: A simple SCM skeleton plugin you can build with Gradle 2.9, very minimalistic, no real functionality.
Source Control and Bug Reporting
The source for the gradle-jpi-plugin is in GitHub, at https://github.com/jenkinsci/gradle-jpi-plugin.