Post on 15-Jan-2017
#jenkinsconf
Plugin Development – It‘s Your Choice
• Build Tool – Maven, Gradle, …
• Programming Language – Java, Groovy, Ruby, Python, …
• Testing – JUnit, Spock, …
#jenkinsconf
Plugin Development – It‘s Your Choice
• Build Tool – Maven, Gradle, …
• Programming Language – Java, Groovy, Ruby, Python, …
• Testing – JUnit, Spock, …
#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
#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 { … }
}
#jenkinsconf
Directory Structure
hello-world-plugin +---build.gradle \---src +---main | +---groovy | \---resources \---test +---groovy \---resources
#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
#jenkinsconf
Further Information
• Documentation https://wiki.jenkins-ci.org/display/JENKINS/Gradle+JPI+Plugin
• Issue Tracker https://issues.jenkins-ci.org/browse/JENKINS/component/16321
• Jenkins Developer Mailing List https://groups.google.com/forum/#!forum/jenkinsci-dev
• Example https://github.com/jenkinsci/job-dsl-plugin
#jenkinsconf
Groovy
• All documentation and examples about plugin development with Java also apply to Groovy
• Jenkins comes with Groovy 1.8
#jenkinsconf
Example
class HelloWorldBuilder extends Builder { final String name
@DataBoundConstructor HelloWorldBuilder(String name) { … } @Override boolean perform(…) { listener.logger.println("Hello, ${name}!")
true } }
#jenkinsconf
Further Information
• Groovy http://www.groovy-lang.org/ http://www.groovy-lang.org/groovy-weekly.html http://glaforge.appspot.com/article/groovy-presentations-at-conferences
• Developing Plugins https://wiki.jenkins-ci.org/display/JENKINS/Extend+Jenkins
• Example https://github.com/jenkinsci/hello-world-groovy-plugin
#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()
#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 } }
#jenkinsconf
Further Information
• Documentation http://docs.spockframework.org/
• Testing plugins https://wiki.jenkins-ci.org/display/JENKINS/Unit+Test
#jenkinsconf
Summary – It‘s Your Choice
• Build Tool – Maven, Gradle, …
• Programming Language – Java, Groovy, Ruby, Python, …
• Views – Jelly, Groovy
• Testing – JUnit, Spock, …