CodeConnexx
7 November 2013
Continuous Integration
with Jenkins
Slide 2
Slide 2 text
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
Slide 3
Slide 3 text
https://joind.in/9937 3
CodeConnexx
7 November 2013
About me
●
I am Mike van Riel
@mvriel
Slide 4
Slide 4 text
https://joind.in/9937 4
CodeConnexx
7 November 2013
About me
●
I am Mike van Riel
●
Lead Developer for
phpDocumentor
Slide 5
Slide 5 text
https://joind.in/9937 5
CodeConnexx
7 November 2013
About me
●
I am Mike van Riel
●
Lead Developer for
phpDocumentor
●
Software Composer at
Ingewikkeld
Slide 6
Slide 6 text
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
Slide 7
Slide 7 text
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
Slide 8
Slide 8 text
https://joind.in/9937 8
CodeConnexx
7 November 2013
About
Quality Assurance
Slide 9
Slide 9 text
https://joind.in/9937 9
CodeConnexx
7 November 2013
“Quality Assurance
is more than unit tests”
Slide 10
Slide 10 text
https://joind.in/9937 10
CodeConnexx
7 November 2013
Quality Assurance
●
Automated tests
●
Coding style
●
Monitoring
●
Metrics and trends
Slide 11
Slide 11 text
https://joind.in/9937 11
CodeConnexx
7 November 2013
What is
Continuous Integration?
Slide 12
Slide 12 text
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.
Slide 13
Slide 13 text
https://joind.in/9937 13
CodeConnexx
7 November 2013
Why
Continuous Integration?
Slide 14
Slide 14 text
https://joind.in/9937 14
CodeConnexx
7 November 2013
Why?
●
Automated, less error-prone
●
Continuous, always available
●
Transparent for everyone
●
Reduces defects
Slide 15
Slide 15 text
https://joind.in/9937 15
CodeConnexx
7 November 2013
How does it work?
Slide 16
Slide 16 text
https://joind.in/9937 16
CodeConnexx
7 November 2013
Commit / push CI polls VCS
Rinse and repeat
Run steps
Report failure
Success
Slide 17
Slide 17 text
https://joind.in/9937 17
CodeConnexx
7 November 2013
Which
environment?
Slide 18
Slide 18 text
https://joind.in/9937 18
CodeConnexx
7 November 2013
Environments
●
CruiseControl / phpUnderControl
●
Jenkins
●
Thoughtworks Go
●
Sismo
●
Travis-CI
●
PHPCI
●
Scrutinizer CI
Slide 19
Slide 19 text
https://joind.in/9937 19
CodeConnexx
7 November 2013
Jenkins
Slide 20
Slide 20 text
https://joind.in/9937 20
CodeConnexx
7 November 2013
Jenkins
●
Java application
●
Extensible with a lot of plugins
●
Integrates nicely with PHP QA Tools
Slide 21
Slide 21 text
https://joind.in/9937 21
CodeConnexx
7 November 2013
What can we do
with it?
Slide 22
Slide 22 text
https://joind.in/9937 22
CodeConnexx
7 November 2013
What for?
Mess detection
Automated testing
Copy/paste detection
Various metrics
Coding Standards
API Documentation
Slide 23
Slide 23 text
https://joind.in/9937 23
CodeConnexx
7 November 2013
Automated testing
●
Unit tests
●
Integration or system tests
●
Acceptance tests
Slide 24
Slide 24 text
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
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
Slide 27
Slide 27 text
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
Slide 28
Slide 28 text
https://joind.in/9937 28
CodeConnexx
7 November 2013
Book recommendation
Slide 29
Slide 29 text
https://joind.in/9937 29
CodeConnexx
7 November 2013
PHPDocumentor
●
API Reference Documentation
●
Class Diagram
●
Documentation validation
Especially useful for open source projects
Slide 30
Slide 30 text
https://joind.in/9937 30
CodeConnexx
7 November 2013
Installing
Jenkins
Slide 31
Slide 31 text
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
Slide 32
Slide 32 text
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
https://joind.in/9937 39
CodeConnexx
7 November 2013
Configuring
Jenkins
Slide 40
Slide 40 text
https://joind.in/9937 40
CodeConnexx
7 November 2013
Prime resource
Jenkins-PHP.org
Slide 41
Slide 41 text
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
https://joind.in/9937 45
CodeConnexx
7 November 2013
Adding a project to
Jenkins
Slide 46
Slide 46 text
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
Slide 47
Slide 47 text
https://joind.in/9937 47
CodeConnexx
7 November 2013
Build files
Phing or Ant?
Slide 48
Slide 48 text
https://joind.in/9937 48
CodeConnexx
7 November 2013
Are you ready
to rumble?