Skip to main content

Continous integration with PHP and Jenkins


Continuous integration (CI) is a development practice which allows testing, building and checking the quality of the application in automated way without manual developer intervention. It requires developers to integrate code into a shared repository several times a day or every commit/merge to the given branch of the repository. Each check-in is then verified by an automated build, allowing teams to detect problems early.

While PHP Continuous Integration (PHPCI) does not require the the code compilation as
build” one can understand the set of task like testing and quality checks which are performed in timely manner or when the certain conditions are met.
PHPCI can be performed on Jenkins Server. The detailed description of jenkins server configuration in is presented here. PHPCI requires PHing package which can be provided into application by Composer.

“PHing Is Not GNU make” is a PHP project build tool based on Apache Ant. It uses simple XML build files which make it an easy-to-use and highly flexible build framework.
Typical PHPCI configuration allows you to test every commit your team decided to merge to the “master” or “stage” branch. It makes passes all your unit tests and check if the code meets your standards.

The build is configured in build.xml file which is quite self-explanatory. Other xml files may be required to configure so called “targets” - the task which are performed every build. The best way to provide php related targets is to install them by the composer. This way no alterations on Jenkins Server are needed:

In the example configurarion presented on GitHub  the following extensions are installed:

Phing: (described above) - the tool chosen to build and manage the project
PHPUnit - provides the unit tests framework.
CodeSniffer - provides syntax check for the project.
PHPMD - detects possible problems and complexity throughout the code.
PHPLoc - does a summary of how much lines of code, classes, etc the code has.
PHPDepend - is used to analyze dependencies between the different modules of the application.
PHPDox - php documentation generator
PHPloc - quickly measuring the size and analyzing the structure of a PHP project.
Interpretation of the build results

Each build is described by two basic icons which are “Status” (S) and “Weather” (W). Every successful build is indicated by green light in the status column. The problem with build is indicated by red light. The weather status shows the progressive status of the several last builds. The cloudy weather means that build is not stable and several last builds might have been unsuccessful. Sunny weather indicates stable projects.

Even successful build is worth analyzing by looking at two charts: Abstraction Instability Chart and Overview Pyramid:

The Abstraction Instability Chart chart as it is generated by PHPDepend is based on the whitepaper OO Design Quality Metrics. It shows the quality of design in the terms of extensibility, reusability and maintainability. All these facts are influenced by the inter-package dependencies and the package abstraction.
The Overview Pyramid is used to visualize a complete software system in a really compact manner. Therefore it collects a set of metrics from the categories like:  Inheritance, Coupling and Size & Complexity, and puts them into relation. The Overview Pyramid provides a simple and size independent way to get a first impression of a software system, and this without an expensive source code analysis. Thus the Overview Pyramid is an effective tool for a first cost estimate for an unknown system.
If the application is built on the top of the framework the Abstraction Instability Chart and Overview Pyramid usually shows more relevant results for the framework then to our code. To limit the results to code developed in your team it is possible to limit the project base dir in build.xml file.
The detailed metrics are described here.
Code Complexity warnings and Duplicate Code warnings are available after clicking on the build link.
If the build fails one can be interested what is the root cause of the red light in jenkins. This can be done by accessing the build console. The console output shows detailed description of how the build was performed, which unit tests failed, the PHP warnings and notices and so on.

Setting up Jenkins

In case of the build problem the debugging on local machine may be required. On the local machine the build can be simulated by running phing from the command line. Being in the root directory of app which contain phing installed by composer you can run:
The PHing will perform exactly the same build process as on the Jenkins server.
Developer can also install Jenkins locally in order to test continuous integration on development machine before the project is deployed to continuous integration server:

apt-get install jenkins
# Prepare jenkins command line tool
wget http://localhost:8080/jnlpJars/jenkins-cli.jar
# install jenkins modules
java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin checkstyle cloverphp dry htmlpublisher jdepend plot pmd violations xunit git bitbucket
java -jar jenkins-cli.jar -s http://localhost:8080 safe-restart
sudo apt-get install curl
# install the template
java -jar jenkins-cli.jar -s http://localhost:8080 safe-restart

To create Jenkins job in GUI go to Jenkins then choose:

  1. New Item -> Freestyle project -> git
  2. Add jenkins credential (login and private key)
  3. Check "Build when a change is pushed to BitBucket"
  4. Add build Step "Execute shell" and paste “vendor/bin/phing -logger phing.listener.NoBannerLogger"
  5. Save Job

Other Relevant Information

PHP Continuous integration benefits a lot from the unit tests. To get the best results team need to remember to keep level of the unittest close to 100% or above 100% coverage.

Setting up PHing configuration for the new project can be as easy as copying the build.xml file from existing project. Developer need to remember to add required targets to the composer.json file and properly bootstrap the PHPUnit and PHing. Also the proper permission need to be set in the project so temporary “build” directory can be created by Jenkins.
Post a Comment

Popular posts from this blog


Structural genomics is the wide term which describes process of determination of structure representation of information in human genome and at present is limited almost exclusively on proteins. Although in common understanding genetic information means “genes and their encoded protein products”, thousands of human genes produce transcripts which are important in biological point of view but they do not necessarily produce proteins. Furthermore, even though the sequence of the human DNA is known by now, the meaning of the most of the sequences still remains unknown. It is very likely that a large amount of genes has been highly underestimated, mainly because the actual gene finders only work well for large, highly expressed, evolutionary conserved protein-coding genes. Most of those genome elements encode for RNA from which transfer and ribosomal RNAs are the classical examples. But beside these well-known molecules there is a vast unknown world of tiny RNAs that might play a crucial …

Application and implementation of probabilistic profile-profile comparison methods for protein fold recognition

Fold recognition is a method of fold detecting and protein tertiary structure prediction applied for proteins lacking homologues sequences of known fold and structure deposited in the Protein Data Bank. They are based on assumption that there is strictly limited number of different protein folds in nature, mostly as a result of evolution and due to basic physical and chemical constraints of polypeptide chains. Fold recognition methods are useful for protein structure prediction, evolutionary analysis, metabolic pathways and enzymatic efficiency prediction, molecular docking and drug design. Currently there are about 1300 discovered and characterized protein folds in SCOP and CATH databases. Every newly discovered protein sequence has significant chances to be classified into one of those folds. Many different approaches have been proposed for finding the correct fold for a new sequence and it is often useful to include evolutionary information for query as well as for target proteins.…

GPGPU Accelerated Sparse Linear Solver for Fast Simulation of On-Chip Coupled Problems

Continued device scaling into the nanometer region has given rise to new effects that previously had negligible impact but now present greater challenges to designing successful mixed-signal silicon. Design efforts are further exacebated by unprecedented computational resource requirements for accurate design simulation and verification. This paper presents a GPGPU accelerated sparse linear solver for fast simulation of on-chip coupled problems using nVIDIA and ATI GPGPU accelerators on a multi-core computational cluster and evaluate parallelization strategies from a computational perspective.