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

Continuous Integration with Jenkins

Mike van Riel
November 07, 2013

Continuous Integration with Jenkins

A workshop on using Jenkins for Continuous Integration given at the CodeConnexx 2013 conference

Mike van Riel

November 07, 2013
Tweet

More Decks by Mike van Riel

Other Decks in Technology

Transcript

  1. CodeConnexx
    7 November 2013
    Continuous Integration
    with Jenkins

    View Slide

  2. https://joind.in/9937 2
    CodeConnexx
    7 November 2013
    Goals for today

    Introduce Continuous Integration for PHP

    Install Jenkins

    Configure Jenkins for PHP

    Configure a project in Jenkins

    View Slide

  3. https://joind.in/9937 3
    CodeConnexx
    7 November 2013
    About me

    I am Mike van Riel
     @mvriel

    View Slide

  4. https://joind.in/9937 4
    CodeConnexx
    7 November 2013
    About me

    I am Mike van Riel

    Lead Developer for
    phpDocumentor

    View Slide

  5. https://joind.in/9937 5
    CodeConnexx
    7 November 2013
    About me

    I am Mike van Riel

    Lead Developer for
    phpDocumentor

    Software Composer at
    Ingewikkeld

    View Slide

  6. https://joind.in/9937 6
    CodeConnexx
    7 November 2013
    About me

    I am Mike van Riel

    Lead Developer for
    phpDocumentor

    Software Composer at
    Ingewikkeld

    Foster father of two
    cute dogs

    View Slide

  7. https://joind.in/9937 7
    CodeConnexx
    7 November 2013
    Requirements

    Virtual Machine or VPS

    Project with, at least, unit tests

    PHP installed with PEAR

    Java

    View Slide

  8. https://joind.in/9937 8
    CodeConnexx
    7 November 2013
    About
    Quality Assurance

    View Slide

  9. https://joind.in/9937 9
    CodeConnexx
    7 November 2013
    “Quality Assurance
    is more than unit tests”

    View Slide

  10. https://joind.in/9937 10
    CodeConnexx
    7 November 2013
    Quality Assurance

    Automated tests

    Coding style

    Monitoring

    Metrics and trends

    View Slide

  11. https://joind.in/9937 11
    CodeConnexx
    7 November 2013
    What is
    Continuous Integration?

    View Slide

  12. https://joind.in/9937 12
    CodeConnexx
    7 November 2013
    Continuous Integration

    A watchdog guarding your Quality.

    Immediate insight into the state of your
    code-base.

    Detailed overview of possible issues.

    A way of thinking and working.

    View Slide

  13. https://joind.in/9937 13
    CodeConnexx
    7 November 2013
    Why
    Continuous Integration?

    View Slide

  14. https://joind.in/9937 14
    CodeConnexx
    7 November 2013
    Why?

    Automated, less error-prone

    Continuous, always available

    Transparent for everyone

    Reduces defects

    View Slide

  15. https://joind.in/9937 15
    CodeConnexx
    7 November 2013
    How does it work?

    View Slide

  16. https://joind.in/9937 16
    CodeConnexx
    7 November 2013
    Commit / push CI polls VCS
    Rinse and repeat
    Run steps
    Report failure
    Success

    View Slide

  17. https://joind.in/9937 17
    CodeConnexx
    7 November 2013
    Which
    environment?

    View Slide

  18. https://joind.in/9937 18
    CodeConnexx
    7 November 2013
    Environments

    CruiseControl / phpUnderControl

    Jenkins

    Thoughtworks Go

    Sismo

    Travis-CI

    PHPCI

    Scrutinizer CI

    View Slide

  19. https://joind.in/9937 19
    CodeConnexx
    7 November 2013
    Jenkins

    View Slide

  20. https://joind.in/9937 20
    CodeConnexx
    7 November 2013
    Jenkins

    Java application

    Extensible with a lot of plugins

    Integrates nicely with PHP QA Tools

    View Slide

  21. https://joind.in/9937 21
    CodeConnexx
    7 November 2013
    What can we do
    with it?

    View Slide

  22. https://joind.in/9937 22
    CodeConnexx
    7 November 2013
    What for?
    Mess detection
    Automated testing
    Copy/paste detection
    Various metrics
    Coding Standards
    API Documentation

    View Slide

  23. https://joind.in/9937 23
    CodeConnexx
    7 November 2013
    Automated testing

    Unit tests

    Integration or system tests

    Acceptance tests

    View Slide

  24. https://joind.in/9937 24
    CodeConnexx
    7 November 2013
    Mess detection

    Finds possible bugs

    Checks for sub-optimal code

    Warns you for complex code

    Detects unused code

    View Slide

  25. https://joind.in/9937 25
    CodeConnexx
    7 November 2013
    Copy/paste detection

    Prevents copy / paste coding

    Detects refactoring hotspots

    Reduces maintenance costs

    View Slide

  26. https://joind.in/9937 26
    CodeConnexx
    7 November 2013
    PHP Code Sniffer

    Checks for coding style violations

    Helps to improves readability
    – Consistency
    – Best practices

    Comes with PEAR, PSR-1 & PSR-2

    View Slide

  27. https://joind.in/9937 27
    CodeConnexx
    7 November 2013
    PHPloc & PHP_Depend

    Collects many metrics
    – Cyclomatic Complexity
    – N-path Complexity
    – Lines per method
    – Spread of classes
    – And a lot more

    View Slide

  28. https://joind.in/9937 28
    CodeConnexx
    7 November 2013
    Book recommendation

    View Slide

  29. https://joind.in/9937 29
    CodeConnexx
    7 November 2013
    PHPDocumentor

    API Reference Documentation

    Class Diagram

    Documentation validation
    Especially useful for open source projects

    View Slide

  30. https://joind.in/9937 30
    CodeConnexx
    7 November 2013
    Installing
    Jenkins

    View Slide

  31. https://joind.in/9937 31
    CodeConnexx
    7 November 2013
    Installing Jenkins
    Manual
    Installation
    1. Install Java
    2. Download war file
    3. Put on server
    4. Add to boot scripts
    Using a package
    manager
    1. Add Jenkins repository
    2. Update package
    manager
    3. Run installation

    View Slide

  32. https://joind.in/9937 32
    CodeConnexx
    7 November 2013
    Installing requirements
    $ apt-get update
    $ apt-get install curl vim make ant
    daemon bash-completion openjdk-6-jre
    php5-cli php-pear git

    View Slide

  33. https://joind.in/9937 33
    CodeConnexx
    7 November 2013
    Installing tools
    $ pear config-set auto_discover 1
    $ pear install pear.phing.info/phing
    $ pear install pear.phpmd.org/PHP_PMD
    $ pear install pear.phpunit.de/PHPUnit
    $ pear install pear.phpunit.de/phpcpd
    $ pear install pear.phpunit.de/phploc
    $ pear install pear.php.net/PHP_CodeSniffer
    $ pear install pear.phpdoc.org/phpDocumentor

    View Slide

  34. https://joind.in/9937 34
    CodeConnexx
    7 November 2013
    “The next few slides
    demonstrate how you
    would usually install
    Jenkins; but not today”

    View Slide

  35. https://joind.in/9937 35
    CodeConnexx
    7 November 2013
    Installing Jenkins
    $ wget -q -O -
    http://pkg.jenkins-ci.org/debian/jenkin
    s-ci.org.key | sudo apt-key add -
    deb http://pkg.jenkins-ci.org/debian binary/
    Add to /etc/apt/sources.list

    View Slide

  36. https://joind.in/9937 36
    CodeConnexx
    7 November 2013
    Installing Jenkins
    $ apt-get update
    $ apt-get install jenkins

    Why not? Jenkins 1.536 and 1.538 (latest) are broken

    View Slide

  37. https://joind.in/9937 37
    CodeConnexx
    7 November 2013
    “So .. How are we
    going to install
    Jenkins today?”

    View Slide

  38. https://joind.in/9937 38
    CodeConnexx
    7 November 2013
    Installing Jenkins
    $ dpkg -i
    ~/jenkins/jenkins_1.535_all.deb

    View Slide

  39. https://joind.in/9937 39
    CodeConnexx
    7 November 2013
    Configuring
    Jenkins

    View Slide

  40. https://joind.in/9937 40
    CodeConnexx
    7 November 2013
    Prime resource
    Jenkins-PHP.org

    View Slide

  41. https://joind.in/9937 41
    CodeConnexx
    7 November 2013
    Jenkins-PHP.org

    Maintained by Sebastian Bergmann

    Job template for PHP projects

    Provides assistance with instructions

    But: replace phpdox with phpDocumentor

    View Slide

  42. https://joind.in/9937 42
    CodeConnexx
    7 November 2013
    Installing dependencies
    $ wget
    http://localhost:8080/jnlpJars/jenkins-cli.jar
    $ java -jar jenkins-cli.jar -s http://localhost:8080
    install-plugin checkstyle cloverphp dry htmlpublisher
    jdepend plot pmd violations xunit git
    $ jenkins-cli.jar -s http://localhost:8080 safe-restart

    View Slide

  43. https://joind.in/9937 43
    CodeConnexx
    7 November 2013
    Installing dependencies
    $ wget
    https://raw.github.com/sebastianbergmann/php-
    jenkins-template/master/config.xml
    $ java -jar jenkins-cli.jar -s
    http://localhost:8080 create-job php-template
    < config.xml

    View Slide

  44. https://joind.in/9937 44
    CodeConnexx
    7 November 2013
    Configuring Jenkins

    Configure security

    Configure mail settings

    Install additional plugins

    Github

    IRC

    View Slide

  45. https://joind.in/9937 45
    CodeConnexx
    7 November 2013
    Adding a project to
    Jenkins

    View Slide

  46. https://joind.in/9937 46
    CodeConnexx
    7 November 2013
    Setting up a new project
    1. Create a build file
    2. Tell Jenkins to add a new Job
    3. Use a copy of the existing php-template job
    4. Add VCS information and schedule
    5. Enable your Job

    View Slide

  47. https://joind.in/9937 47
    CodeConnexx
    7 November 2013
    Build files
    Phing or Ant?

    View Slide

  48. https://joind.in/9937 48
    CodeConnexx
    7 November 2013
    Are you ready
    to rumble?

    View Slide