By Daniel Spilker, CoreMedia
Learn how to use the Gradle JPI plugin to enable a 100% Groovy plugin development environment. We will delve into Groovy as the primary programming language, Spock for writing tests and Gradle as the build system.
5. #jenkinsconf
Gradle JPI Plugin
• Builds the Jenkins plugin file (HPI / JPI)
• Can be combined with other Gradle plugins
• Hooks into the standard Gradle tasks
• Recommended prerequisites
– Java 7
– Gradle 2.3
6. #jenkinsconf
Example
buildscript { … }
apply plugin: 'org.jenkins-ci.jpi'
group = 'org.jenkins-ci.plugins'
version = '0.0.1-SNAPSHOT'
description = 'A description of your plugin'
jenkinsPlugin {
coreVersion = '1.580'
displayName = 'Hello World'
url = 'http://wiki.jenkins-ci.org/display/JENKINS/Hello+World'
gitHubUrl = 'https://github.com/jenkinsci/hello-world-plugin'
developers { … }
}
8. #jenkinsconf
Gradle Tasks
• gradle server
– Start a Jenkins instance with the plugin installed for
manual testing
• gradle jpi
– Build the Jenkins plugin file
• gradle publish
– Deploy your plugin to the Jenkins Maven repository to
be included in the Update Center
15. #jenkinsconf
Spock Framework
• Spock 0.7 must be used due to Groovy 1.8 constraint
• Gradle dependency declaration
dependencies {
testCompile 'org.spockframework:spock-core:0.7-groovy-1.8'
}
• The Jenkins test harness can be used
@Rule
JenkinsRule jenkinsRule = new JenkinsRule()
16. #jenkinsconf
Example
class ExampleSpec extends Specification {
@Rule
JenkinsRule jenkinsRule = new JenkinsRule()
def 'some example test'() {
setup:
FreeStyleProject job = jenkinsRule.createFreeStyleProject('seed')
when:
FreeStyleBuild freeStyleBuild = job.scheduleBuild2(0).get()
then:
freeStyleBuild.result == SUCCESS
}
}