The document discusses plugin development for Jenkins using Gradle and Groovy. It presents Gradle as a build tool for Jenkins plugins that can generate the plugin file and deploy it. Groovy is highlighted as a programming language that can be used along with Java for plugin development. Spock is recommended as a testing framework that works with the constraints of Groovy 1.8 used in Jenkins. Examples of building, testing, and deploying plugins with Gradle and Groovy are also provided.
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
}
}