Jenkins is a really powerful tool for automating things like code analysis, testing and even deployment. Getting started with Jenkins, especially with Drupal, is a challenge and can be quite difficult for a beginner to the system. In this session I'll show you how to install Jenkins, how to configure things like authentication and then how to do some interesting things with the tool. I'll show some real life examples of things that can be done with the tool on your Drupal sites to do things like run cron jobs, syntax check the code or even automatically copying code to your web servers.
2. Me
•
Phil Norton (@philipnorton42)
•
#! code (www.hashbangcode.com)
•
Technical Lead at Access
•
Help run NWDUG
•
DrupalCampNW2013 co-organizer
•
Help out at PHPNW
#!
3. Jenkins
•
Build and automation server
•
Java application
•
Used to be called Hudson
•
Built for continuous integration
•
Helps you run repetitive tasks
•
http://jenkins-ci.org/
#!
10. Authentication
•
Jenkins doesn’t have authentication when first
installed
•
Probably a good idea to enable it!
•
Many different models from local user credentials
to domain authentication
#!
11. Creating A User In Jenkins
•
Simplest security model for beginners
•
Manage Jenkins > Configure Security > Enable
Security
•
Manage Jenkins > Manage Users > Create User
#!
12. ooopss…
•
Quite easy to lock yourself out
•
Open the file config.xml remove the element
<useSecurity> to remove security
#!
13. Anatomy Of Jenkins
•
Jenkins can be found at /var/lib/jenkins
•
May contain one or more of the following:
.ssh
config.xml
jobs/
nodeMonitors.xml
plugins/
secret.key
secret.key.not-so-secret
updates/
userContent/
users/
workspace/
#!
27. Some Rules For Using
Jenkins With Drupal
•
Use source control
•
Only analyse your own code as priority
•
Know what you are analysing
•
Understand the output
•
Standardise as much as you can
#!
29. Git
•
Use source control to pull code into Jenkins
•
To use Git you need the Jenkins Git plugin
•
Best results are using SSH (you will also need
some ssh keys)
•
Perhaps the most complex part of the job setup
#!
30. Git
•
Use source control to pull code into Jenkins
•
To use Git you need the Jenkins Git plugin
•
Best results are using SSH (you will also need
some ssh keys)
•
Perhaps the most complex part of the job setup
#!
31. Add your git ssh URL to Jenkins
Jenkins will give you a warning if it can’t see the repo
#!
33. PHP Lint
•
Syntax check any PHP file with
php -l myfile.php
•
Can only do one file at a time
•
How can we check an entire project?
#!
34. •
Build tool
•
Controlled with XML files
•
Written in PHP
•
Available through PEAR
•
Integrates with Jenkins
•
Certified awesome!
#!
35.
36. Phing And PHP Lint
•
Add a Phing build file to your source code
•
What we need to do is:
1. Tell Phing what files we want to scan
2. Use the phplint Phing task to scan files
3. Fail the build if any errors found
#!
38. Running Phing
Syntax Check
Syntax Check
•
Add the Phing file to your source code as
build.xml
•
You can run this build using the following:
phing -f scripts/build.xml syntaxcheck_php
#!
39. Add Phing Build Step To
Jenkins
•
Use the Jenkins Phing Plugin to invoke the
syntaxcheck_php Phing target
#!
43. PHP CodeSniffer
•
Inspect code for Drupal coding standards
•
Produces checkstyle.xml files for Checkstyle
•
Looks for best practice in your code
#!
44. Install PHP CodeSniffer
•
Install the PHP CodeSniffer package
sudo pear install PHP_CodeSniffer
•
Download Coder and link the Drupal CodeSniffer
standard
drush dl coder
sudo ln -sv /path/to/coder/coder_sniffer/Drupal
$(pear config-get
php_dir)/PHP/CodeSniffer/Standards/Drupal
#!
50. The Missing Element?
•
Git stores the code
•
phpcs produces the reports
•
Jenkins and processes reports
•
What fits all these elements together?
#!
52. phpcs Phing Module
•
Tell Phing what files we want to scan
•
Use the phpcs Phing module to scan the files
and what standard to use
•
Output the report in a checkstyle.xml file
#!
61. Try It Yourself
•
PHP Mess Detect Phing output into PMD
Analysis Results graphs in Jenkins
•
PHP Copy Paste Detect Phing output into
Duplicate Code Analysis results graphs in
Jenkins
#!
62. Do More!
•
Use Phing to run an action
•
Use Jenkins to automate it
— or —
•
Use Phing to generate reports
•
Use Jenkins plugins to convert reports into
graphs
#!
64. Me
•
Phil Norton (@philipnorton42)
•
#! code (www.hashbangcode.com)
•
Technical Lead at Access
•
Help run NWDUG
•
DrupalCampNW2013 co-organizer
•
Help out at PHPNW
#!