drupal jenkins2014sep13

39
Doin’ it (Leeroy) ----Jenkins Style! Drupal, Jenkins and Continuous Integration Drupal Camp Chattanooga September 13, 2014 Presented by Lisa Ridley Friday, September 12, 14

Upload: lisa-ridley

Post on 22-Apr-2015

311 views

Category:

Technology


0 download

DESCRIPTION

Doin' it (Leeroy) Jenkins Style! Drupal, Jenkins and Continuous Integration Drupal Camp Chattanooga September 13, 2014 Continuous Integration is the "best" practice of merging developer works-in-progress into a single project several times a day, building a test site out of the merged codebase, testing the site, publishing the results of the tests, and ultimately deploying a site. Automatically. In this session, we'll cover how you can set up and use a Jenkins CI server to automate your integration and development testing process using the "Jenkins Job Template for Drupal Projects", a template developed and made available publicly by Reload!, a Drupal development agency located in Copenhagen, Denmark. We'll cover configuring your project template, setting up your Drupal project, configuring your build properties and finally, running a successful build, with test results.

TRANSCRIPT

Page 1: Drupal jenkins2014sep13

Doin’ it (Leeroy) ----Jenkins Style!

Drupal, Jenkins and Continuous Integration

Drupal Camp ChattanoogaSeptember 13, 2014

Presented by Lisa Ridley

Friday, September 12, 14

Page 2: Drupal jenkins2014sep13

About meLisa H. Ridley

Drupal Developer for 4 years, PHP for 9 years

15 years project management

You can find me:

- Drupal.org: lhridley- LinkedIn: linkedin.com/ln/lisa.h.ridley- blog: www.codementality.com- GitHub: https://github.com/lhridley

Friday, September 12, 14

Page 3: Drupal jenkins2014sep13

Who the heck is Leeroy Jenkins?

Internet meme for WoW character created by Ben Shultz

Made famous in the WoW gaming community in an internet video titled “A Rough Go”, about a failed guild melee attack

Friday, September 12, 14

Page 4: Drupal jenkins2014sep13

Why is he here?

Ran across it while googling for information on Jenkins CI

Thought it would make a cool title for this presentation

Friday, September 12, 14

Page 5: Drupal jenkins2014sep13

What is Jenkins?

Build and automation server

- Java application

Built for continuous integration

Awesome for repetitive tasks

http://www.jenkins-ci.org

Friday, September 12, 14

Page 6: Drupal jenkins2014sep13

Friday, September 12, 14

Page 7: Drupal jenkins2014sep13

Installing JenkinsEach platform is different

Check out jenkins-ci.org

- Find your platform on the right hand side of the home page

- Follow the instructions

For Debian based builds

- “Continuous Integration on a Budget” series on www.codementality.com

Friday, September 12, 14

Page 8: Drupal jenkins2014sep13

General Installation/ Hardware Guidelines

LAMP server running php 5.3+, Apache 2.2+, MySQL 5.1+

Git

2G RAM

30G HD Space

2 CPU cores

PHP’s “safe mode” must be disabled

Friday, September 12, 14

Page 9: Drupal jenkins2014sep13

What can Jenkins Do?Inspect your code

Run cron

Build documentation

Test drush make files

Run tests

Deploy sites

Build project profiles

Test Drupal install profiles

If you can standardize it, you can automate it, and Jenkins can help

Friday, September 12, 14

Page 10: Drupal jenkins2014sep13

AuthenticationOut of the box, Jenkins doesn’t have it

Easy to enable and configure

Different authentication methods available:

- Built-in (jenkins database)- Unix user/group database- LDAP- Others available with plugins

Friday, September 12, 14

Page 11: Drupal jenkins2014sep13

Jenkins EcosystemLike Drupal, Jenkins has a thriving community of users and developers

Many plugins are available to extend functionality (Drupal-speak: modules)

- Easy to install with the Plugin Manager

You will use some of them for performing certain testing tasks

Friday, September 12, 14

Page 12: Drupal jenkins2014sep13

Some Useful PluginsGIT/GiT client plugins

JUnit plugin

Matrix Authorization Strategy Plugin

PHing Plugin

Checkstyle

Email notification

Plot Plugin

PMD plugin

Publish over SSH

Static Analysis Collector

Duplicate Code Scanner

SSH Credentials

Friday, September 12, 14

Page 13: Drupal jenkins2014sep13

Jenkins Job List

Friday, September 12, 14

Page 14: Drupal jenkins2014sep13

Basic Drupal Code Analysis

Syntax checking

Drupal Coding Standards violations

Duplication of Code

Code Complexity

Code Tests (SimpleTest in D7, Unit & Functional tests in D8)

Friday, September 12, 14

Page 15: Drupal jenkins2014sep13

Guidelines for Using Jenkins with Drupal

Use Source control

Only analyze your own code

- Don’t spend time checking Drupal Core or contrib modules

Know what you’re analyzing

Understand the output

Standardize, Standardize, Standardize

Friday, September 12, 14

Page 16: Drupal jenkins2014sep13

Standardize…Repository Structure

Drupal Setup

Module file naming conventions/structure

Theme structure

Standardization is the Key to Automation

Friday, September 12, 14

Page 17: Drupal jenkins2014sep13

Jenkins doesn’t do this alone….

PHing -- PHP Project build tool based on Apache Ant

- Runs automated PHP tests (PHPUnit / SimpleTest)

- Performs source control operations (GIT / SVN)

- Generates documentation

- Executes Drush commands

- And more

Friday, September 12, 14

Page 18: Drupal jenkins2014sep13

Jenkins doesn’t do this alone….

PHP Lint -- PHP Syntax Checker

PHPUnit / SimpleTest (Testing)

PHP Mess Detector (Code complexity)

PHP Copy/Paste Detector (Duplicate Code)

PHP Lines of Code (Code Length and Complexity)

PHP Code Sniffer (Style Checker)

Configuring your build file for PHing is key!

Friday, September 12, 14

Page 19: Drupal jenkins2014sep13

Configuring PHing Build files is somewhat complicated...

...and the Drupal Community comes to the rescue!

Friday, September 12, 14

Page 20: Drupal jenkins2014sep13

Jenkins Job Template for Drupal Projects

Developed by Reload!

- Drupal shop in Copenhagen, Denmark

Based on Sebastian Bergman’s “Template for Jenkins Jobs for PHP Projects”

Licensed under Creative Commons Attribution - ShareAlike 3.0 Unported License

http://reload.github.io/jenkins-drupal-template

Friday, September 12, 14

Page 21: Drupal jenkins2014sep13

PHing Drupal Template

XML build file for PHing designed for Drupal projects

Also developed by Reload!

Works with the Jenkins Job Template for Drupal Projects

Friday, September 12, 14

Page 22: Drupal jenkins2014sep13

What tools does the PHing Drupal Template use?

Drush

PHPLoc

JSLint

CSSLint

Coder

Mozilla Rhino

Coder module & PHP CodeSniffer

PHPMD

PHPCPD

Friday, September 12, 14

Page 23: Drupal jenkins2014sep13

How do I get started?

Set up a Jenkins server & Configure to work with your Git repo

Install tools (Phing, PHPMD, etc)

Install Reload!‘s Drupal Job Template

You only have to do this once!

Friday, September 12, 14

Page 24: Drupal jenkins2014sep13

Then what?Set up a Drupal project

Add the build.xml, build.default.properties and build.properties files

Commit to Git

Configure your build server for a new subdomain

Create a new Jenkins Job from the Drupal Job Template

Run it!

Friday, September 12, 14

Page 25: Drupal jenkins2014sep13

What Else?Learn from my mistakes

Visit www.codementality.com, read “Continuous Integration on a Budget” series for help setting up Jenkins, PHing and analysis tools

Use my sanitized templates

Friday, September 12, 14

Page 26: Drupal jenkins2014sep13

Sanitized Templates?

https://github.com/lhridley/drupal7-jenkins-templates

A few added features from the originals by Reload!

Cleaned some hidden characters that caused build headaches to start

Friday, September 12, 14

Page 27: Drupal jenkins2014sep13

Sound Great?

Let’s see it in action!

Friday, September 12, 14

Page 28: Drupal jenkins2014sep13

What just happened?Jenkins kicked off PHing

PHing pulled your drupal project from your code repository

PHing used that to build a drupal site at the URL you provided using your code and a new database using the credentials you provided (more on this in a minute)

PHing executed a number of analysis tools on your codebase (syntax checking, duplicate code check, Drupal coding standards compliance, debug statement detection, etc.)

PHing executed any available SimpleTest test cases for the code you wanted tested

PHing published the results of those tests

Jenkins graphed those results

Friday, September 12, 14

Page 29: Drupal jenkins2014sep13

build.xml

Resides in the build/ directory, which you create in the root directory of your Drupal installation

Houses all of the build instructions for PHing to build a test site and run code analysis and tests

Uses variables contained in build.default.properties and overridden by build.properties

Friday, September 12, 14

Page 30: Drupal jenkins2014sep13

build.xml (cont.)Also contains instructions to build documentation from docBlocks using phpDocumenter

- Skipped due to time and CPU intensity

- Can be added back by editing build.xml and adding “docs” to the “depends” parameter on line 15

Friday, September 12, 14

Page 31: Drupal jenkins2014sep13

build.default. properties

Resides in the build/ directory of your Drupal installation

Holds the default values used by build.xml

Can be overridden with values placed in build.properties

Friday, September 12, 14

Page 32: Drupal jenkins2014sep13

build.properties

Resides in the root directory of your Drupal installation

Overrides any default settings in build/build.default.properties

Provides values specific to your Drupal installation

Friday, September 12, 14

Page 33: Drupal jenkins2014sep13

build.properties variablesphing.project.name

drupal.version

drupal.profile

drupal.admin.email

drupal.admin.name

drupal.admin.pass

drupal.sitename

drupal.sitemail

drupal.uri

drupal.rewritebase

project.code.dir

project.code.prefix

project.code.custom

drupal.db.url

...plus any variable you add from build.default.properties

Friday, September 12, 14

Page 34: Drupal jenkins2014sep13

Key Variablesphing.project.name: the unique project name for your project.

drupal.version: the version of drupal you are testing (6 or 7)

drupal.profile: the install profile you want used to build your test site (standard, minimal, or a custom profile)

drupal.admin.email: the superadmin account email

drupal.admin.name: the superadmin username

drupal.admin.pass: the superadmin password

Friday, September 12, 14

Page 35: Drupal jenkins2014sep13

Key Variablesdrupal.sitename: the site name you want created for your test site

drupal.sitemail: the email address for mail sent from the test site

drupal.uri: the browser address for your test site

drupal.rewritebase: the Base URL for your drupal installation

project.code.dir: the main directory where files & modules to be tested reside (themes & modules)

Friday, September 12, 14

Page 36: Drupal jenkins2014sep13

Key Variablesproject.code.prefix: the “Group” name you use on all of your SimpleTest test cases for your custom code. These tests will be executed, and code will be analyzed

project.code.custom: any modules not included in the “Group” for which you want tests executed & code analyzed

drupal.db.url: database information in URI format for the test database:

- mysql://username:password@host[:port]/databasename

- sqlite://path/to/database/databasename.sqlite

Friday, September 12, 14

Page 37: Drupal jenkins2014sep13

What else can we do?Automate Deployments

Automate Project setup

Run cron jobs

Trigger backups

And more…….

Friday, September 12, 14

Page 38: Drupal jenkins2014sep13

CI is your friend

For more on Jenkins, PHing, Drupal Testing and Continuous Integration, stop in after lunch for our “Birds of a Feather” discussion

BOF - Jenkins and CI, Room 1006, 3pm

Friday, September 12, 14

Page 39: Drupal jenkins2014sep13

Lisa Ridley

Drupal.org: lhridley

Blog: www.codementality.com

github.com/lhridley

Linked In: linkedin.com/ln/lisa.h.ridley

Thanks for coming!

Friday, September 12, 14