Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JUC2014 - High Quality Plugins

JUC2014 - High Quality Plugins

Talk held on Jenkins User Conference 2014 - Berlin, together with Christian Langmann about High Quality Plugins
Strategies for developing a plugin and how to manage them on production environment.

skylab

June 25, 2014
Tweet

More Decks by skylab

Other Decks in Programming

Transcript

  1. Jenkins User Conference Europe #jenkinsconf High Quality Plugins Robert Hostlowsky,

    Christian Langmann codecentric AG http://www.codecentric.de June 25, 2014 #jenkinsconf
  2. Jenkins User Conference Europe #jenkinsconf Agenda What is quality, actually?

    How can we create high- quality plugins? I‘m Ops. Can I do anything?
  3. Jenkins User Conference Europe #jenkinsconf A (hundred) definition of Quality

    „Conformance to requirements." (Philip B. Crosby) „Degree to which a set of inherent characteristics fulfills requirements.“ (ISO9000) „Products and services that meet or exceed customers' expectations."(Noriaki Kano) „Value to some person“ (Gerald M. Weinberg) „A combination of quantitative and qualitative perspectives for which each person has his or her own definition; examples [...]. In technical usage, quality can have two meanings: a. The characteristics of a product or service that bear on its ability to satisfy stated or implied needs; b. A product or service free of deficiencies.“ (American Society for Quality) Excerpt from http://en.wikiepedia.org/wiki/Quality_(business)
  4. Jenkins User Conference Europe #jenkinsconf Do testing … because as

    a plugin submitter, you want happy users and you become unhappy from bug reports from angry testers - ähm users … http://makeameme.org/meme/but-happy-cat
  5. Jenkins User Conference Europe #jenkinsconf What is a Low-Quality-Plugin? •

    Failing: Not doing what was promised ... • Doing something else (deploy to prod instead of stage), wrong version number • Worse: breaking other things, crashing whole system • using a lot of resources: memory, CPU, IO • or just hanging... • Creating non-usable UI
  6. Jenkins User Conference Europe #jenkinsconf Avoid the “Low-Quality”-things • Code

    defensive, robust. ◦ always assume data could be wrong -> check! • Clean Code Principles ◦ SOLID, Test First, Refactoring • Tools for code analysis ◦ Findbugs, PMD, SonarQube • Assume “hostile” environments ◦ handle missing network, timeouts ... … Software Craftsmanship ...
  7. Jenkins User Conference Europe #jenkinsconf Do automated tests Besides simple

    manual testing… You better create automatic tests. But How? • Basic: unit testing • Advanced: acceptance testing You could also do • Performance testing • Testing with restricted resources
  8. Jenkins User Conference Europe #jenkinsconf With plugin-generator created Plugin (implementing

    just a Builder) public class HelloWorldBuilder extends Builder { public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) { // shows how you can consult the global configuration of the builder if (getDescriptor().getUseFrench()) listener.getLogger().println("Bonjour, "+name+"!"); else listener.getLogger().println("Hello, "+name+"!"); return true; } } https://github.com/lowsky/high-quality- plugin/blob/master/src/main/java/org/jenkinsci/plugins/high_quality/HelloWorldBuilder.java Simple Example
  9. Jenkins User Conference Europe #jenkinsconf Basic Unit Testing - Mocked

    Jenkins Env @Test @WithoutJenkins public void performPrintsHelloMessageUnitTest() { AbstractBuild build = Mockito.mock(AbstractBuild.class); BuildListener listener = Mockito.mock(BuildListener.class); Launcher launcher = Mockito.mock(Launcher.class); ByteArrayOutputStream outStream = new ByteArrayOutputStream(1000); PrintStream logger = new PrintStream(outStream); when(listener.getLogger()).thenReturn(logger); HelloWorldBuilder worldBuilderSpy = Mockito.spy(worldBuilder); doReturn(false).when(worldBuilderSpy).useFrench(); boolean performed = worldBuilderSpy.perform(build, launcher, listener); Mockito.verify(worldBuilderSpy).printLogMsg(false, logger); assertThat("perform shall return true.", performed, is(true)); assertThat(outStream.toString(), containsString(expectedMsg)); } https://wiki.jenkins-ci.org/display/JENKINS/Unit+Test
  10. Jenkins User Conference Europe #jenkinsconf Basic Unit Testing - within

    Jenkins Env @Rule public JenkinsRule jenkinsRule = new JenkinsRule(); @Test public void performPrintsHelloMessageWithJut() throws Exception { FreeStyleProject dummy = jenkinsRule.createFreeStyleProject("dummy"); dummy.getBuildersList().add(worldBuilder); jenkinsRule.buildAndAssertSuccess(dummy); Run lastRun = dummy._getRuns().newestValue(); jenkinsRule.assertLogContains(expectedMsg, lastRun); } https://wiki.jenkins-ci.org/display/JENKINS/Unit+Test
  11. Jenkins User Conference Europe #jenkinsconf Simple Web Based Testing (classic)

    HtmlUnit htmlPage = jenkins.getWebclient().goto(“/config”); WebAssert.assertElementPresent(page, "hudson-scm-CVSSCM"); Use case, example:
  12. Jenkins User Conference Europe #jenkinsconf Acceptance Driven Testing Acceptance Test

    Harness (see GitHub) announcement: http://jenkins-ci.org/content/acceptance-test-project-progress-report
  13. Jenkins User Conference Europe #jenkinsconf Acceptance Test Harness features: •

    ATDD testing based on cucumber feature tests. • A lot of re-usable PageObjects/Areas, like globalConfiguration, builderSection, jobs, etc… • Can use docker for simple test fixtures! • different browser support Huge Test Suite for the LTS releases! Acceptance Driven Testing
  14. Jenkins User Conference Europe #jenkinsconf Managing my environment... Never touch

    a running environment... ... nice idea ... leads to an antiquated system: - „I still have H...n in a version before the fork“ - „New plugins don‘t work in my old environment anymore“ - „I don‘t even know how many Jenkins we have setup with which plugins“
  15. Jenkins User Conference Europe #jenkinsconf Moving to a controlled environment

    Find out, which Plugins are used ⇒ Click through Jenkins instances ⇒ Analyse config.xml ⇒ Plugin Usage Plugin
  16. Jenkins User Conference Europe #jenkinsconf Handle updates carefully When updating,

    check configuration changes ⇒ use JobConfigHistory-Plugin ⇒ verify system and job config
  17. Jenkins User Conference Europe #jenkinsconf Jenkins PROD Jenkins PROD Staging

    of Plugins • Plugin-Versions (or Jenkins-Core-Versions) are staged • Once a quality is reached, a plugin is installed to next stage • Complexity increases with number of stages and different production setups Jenkins DEV Jenkins INT Jenkins TEST Jenkins PROD 2.1 2.0 1.5 1.4
  18. Jenkins User Conference Europe #jenkinsconf Jenkins PROD Jenkins PROD Use

    Custom-Update-Sites Jenkins DEV Jenkins INT Jenkins TEST Jenkins PROD 2.1 2.0 1.5 1.4 US 2.1 2.0 1.5 1.4 1.4
  19. Jenkins User Conference Europe #jenkinsconf US Jenkins PROD Jenkins PROD

    Use Update-Site per environment Jenkins DEV Jenkins INT Jenkins TEST Jenkins PROD 2.1 2.0 1.5 1.4 US 1.4 1.4 1.5 US 1.4 1.5 2.0 Promote Versions Supporting Plugins • UpdateSites Manager Plugin • SimpleUpdateSite Plugin
  20. Jenkins User Conference Europe #jenkinsconf Using Update Centers Promote Plugins

    Install Plugins Install Plugins Define Update-Strategy and Quality-Gates (e.g. LTS vs. latest) for each stage Manage updates centrally • Jenkins Update Center (CloudBees Enterprise Plugin) • Jenkins Operations Center (CloudBees)