Due to some maintenance issues, this service has been switched in read-only mode, you can find more information about the why

and how to migrate your plugin documentation in this blogpost

Skip to end of metadata
Go to start of metadata

Introduction

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.

Requirements

  • 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.

Setup

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:

plugins {
  id "org.jenkins-ci.jpi" version "0.16.0"
}

group = "org.jenkins-ci.plugins"
version = "0.0.1-SNAPSHOT"    // Or whatever your version is.
description = "A description of your plugin"

jenkinsPlugin {
    coreVersion = "1.420"                                               // Version of Jenkins core this plugin depends on.
    displayName = "Hello World plugin built with Gradle"                // Human-readable name of plugin.
    url = "http://wiki.jenkins-ci.org/display/JENKINS/SomePluginPage"   // URL for plugin on Jenkins wiki or elsewhere.
    gitHubUrl = "https://github.com/jenkinsci/some-plugin"              // Plugin URL on GitHub. Optional.
    shortName = "hello-world"                                           // Plugin ID, defaults to the project name without trailing '-plugin'

    // The developers section is optional, and corresponds to the POM developers section.
    developers {
        developer {
            id "abayer"
            name "Andrew Bayer"
            email "andrew.bayer@gmail.com"
        }
    }
}

Make sure any additional repositories you need are defined after the jenkinsPlugin section, or artifact resolution may take a long time.

Usage

Building

To build, run gradle jpi. This will create a .hpi file in the build/libs directory in your plugin project directory.

Testing

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 gradle publish.

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 gradle publishToMavenLocal.

Debugging

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.

$ export GRADLE_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
$ ./gradlew server

Releasing

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-plugin-0.0.1, where 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:

userName=yourusername
password=yourpassword

Dependencies on other Jenkins Plugins

If your plugin depends on other Jenkins plugins you can specify the dependencies in the following way:

dependencies {
    jenkinsPlugins 'org.jenkinsci.plugins:git:1.1.15@jar'
    optionalJenkinsPlugins 'org.jenkins-ci.plugins:ant:1.2@jar'
    jenkinsTest 'org.jenkins-ci.main:maven-plugin:1.480@jar'
}

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 jenkinsTest configuration.

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).

Examples

Changelog

See CHANGELOG.md.

Source Control and Bug Reporting

The source for the gradle-jpi-plugin is in GitHub, at https://github.com/jenkinsci/gradle-jpi-plugin.

If you run into bugs or have improvements to suggest, you can open an issue at the Jenkins JIRA. Make sure to set the component to gradle-jpi-plugin. You can also review open issues.

  • No labels

2 Comments

  1. Unknown User (alskor)

    thank you for implementing this plugin! one thing I noticed is that Jenkins started through "gradle server" is very slow. I see it is using a lot of CPU time.

    if I stop it and run Jenkins from a regular WAR file, it works fast.

  2. Unknown User (kacalica)

    how up to date is this? 

    My plugin works if I run it from maven or place it into a Jenkins docker instance, but not when I try gradle server

    Also for anyone whose trying gradle server you can change the instance of the Jenkins instance it serves up by changing the core version number in jenkinsPlugin block coreVersion = "1.420" // Version of Jenkins core this plugin depends on.