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

Continuous Integration for PHP with Jenkins and Sonar

Continuous Integration for PHP with Jenkins and Sonar

Presented at GeekCampSG on 18 August 2012.

Michael Cheng

August 18, 2012
Tweet

More Decks by Michael Cheng

Other Decks in Programming

Transcript

  1. Continuous Integration for PHP
    with Jenkins & Sonar
    GeekCampSG, Aug 18, 2012
    1
    Saturday, 18 August, 12

    View Slide

  2. • What is Continuous Integration?
    • What is Jenkins?
    • What is Sonar?
    • QA Tools for PHP
    • Demo
    • http://bit.ly/geekcampsg-ci-php
    Agenda
    2
    Saturday, 18 August, 12

    View Slide

  3. What is Continuous Integration?
    • Continuous integration (CI) implements continuous processes of
    applying quality control — small pieces of effort, applied frequently.
    • Quality control as a continuous process - in small chunks
    rather than at the end of a development cycle / iteration.
    • Merging of smaller manageable change sets instead of large ones.
    3
    Saturday, 18 August, 12

    View Slide

  4. Important Ingredients
    • Version Control Software for your source code (Git, SVN, Darcs).
    • Self-Testing Code. (eg. Unit Tests, BDD, Selenium)
    • Agreement on Agile processes to adopt (in your team).
    • Bonus:
    • Project Management Tool. (eg. Pivotal Tracker, JIRA)
    • Branching Strategy (for development & deployment)
    4
    Saturday, 18 August, 12

    View Slide

  5. Continuous Integration in Action
    • Checkout mainline from code repository.
    • Write tests. Fail tests. Write Code. Pass tests. Refactor. (TDD, BDD)
    • Commit locally. Pull changes. Resolve merge conflicts.
    • Run full suite of tests locally. Push commits to server.
    • CI runs automated tests & builds. (If fail, fix it ASAP)
    5
    Saturday, 18 August, 12

    View Slide

  6. Getting the most out of CI
    • Keep stories small & granular (smaller change sets).
    • Merge early, merge often.
    • Reduce the pain of resolving conflicts later.
    • Write tests that runs fast.
    • Use Mocks and test doubles as much as you can.
    • Automate, Automate, Automate. (or one click action).
    6
    Saturday, 18 August, 12

    View Slide

  7. What is Jenkins CI?
    • Application that monitors executions of repeated jobs, such as
    building a software project or jobs run by cron.
    • Building/testing software projects continuously.
    • Monitoring executions of externally-run jobs.
    • http://jenkins-ci.org/
    7
    Saturday, 18 August, 12

    View Slide

  8. What is Sonar?
    • Sonar is an open platform to manage code quality. As such, it covers
    the 7 axes of code quality:
    • http://www.sonarsource.org/
    8
    Saturday, 18 August, 12

    View Slide

  9. What is Sonar?
    9
    Saturday, 18 August, 12

    View Slide

  10. QA Tools for PHP
    • Template for Jenkins Jobs for PHP Projects by Sebastian
    Bergmann (of PHPUnit fame)
    • Kitchen sink of Quality Assurance tools.
    • Build automation with Apache Ant.
    • Compile PHP? No... :( (unless u use HipHop)
    • http://jenkins-php.org/
    10
    Saturday, 18 August, 12

    View Slide

  11. QA Tools for PHP
    • Checkstyle (for processing
    PHP_CodeSniffer logfiles in
    Checkstyle format)
    • DRY (for processing phpcpd logfiles
    in PMD-CPD format)
    • PMD (for processing PHPMD
    logfiles in PMD format)
    • JDepend (for processing
    PHP_Depend logfiles in JDepend
    format)
    • xUnit (for processing PHPUnit
    logfiles in JUnit format)
    • Violations (for processing various
    logfiles)
    • Clover PHP (for processing
    PHPUnit code coverage xml output)
    • HTML Publisher (for publishing the
    PHPUnit code coverage report, for
    instance)
    • Plot (for processing phploc CSV
    output)
    11
    Saturday, 18 August, 12

    View Slide

  12. Demo
    12
    Saturday, 18 August, 12

    View Slide

  13. Installation
    • OS that supports Java (eg. CentOS)
    • Java
    • Install Jenkins
    • Install PHP-QA tools
    • Install Sonar
    • Add your project (Make sure build server supports your VCS)
    13
    Saturday, 18 August, 12

    View Slide

  14. About Me
    • Michael Cheng
    • Senior Software Engineer, mig33 (http://mig33.com)
    • Contactable at:
    • http://sg.linkedin.com/in/miccheng
    • http://b.mig33.com/u/miccheng
    • http://twitter.com/coderkungfu
    • https://www.facebook.com/groups/sghypertextpreprocessors/
    14
    Saturday, 18 August, 12

    View Slide

  15. http://bit.ly/geekcampsg-ci-php
    https://speakerdeck.com/u/miccheng/
    15
    Saturday, 18 August, 12

    View Slide