Build Symfony2 projects using Jenkins

Original author: Ilia Shakitko
  • Transfer
  • Tutorial
Translation of my article on how to configure builds for PHP projects based on Symfony2 using Jenkins. Recently, I was faced with the task of such a setup specifically for the Symfony 2.1 + Jenkins + PHPUnit + PHPCodeSniffer + PHPMessDetector + PDepend suite.

I hope this short article can be useful!



Today I will tell you how to install and configure the assembly for Symfony2 projects using Jenkins and the PHP template for Jenkins projects created by Sebastian Bergmann .

The configuration works stably with Jenkins v.1.480.1 and projects based on the Symfony v.2.1 framework .

Requirements



Before creating a project template, you need to install the required plugins for Jenkins (Required Jenkins Plugins) and the required PHP tools (Required PHP Tools).

Using PHP template for Jenkins projects



The first steps are based on this article , but we will use config.xml , build.xml , phpunit.xml and additional files taken from this source: github.com/xurumelous/symfony2-jenkins-template .
  1. download jenkins-cli.jar from your Jenkins server:
    wget http://localhost:8080/jnlpJars/jenkins-cli.jar
  2. download and install the project template:
    curl https://github.com/xurumelous/symfony2-jenkins-template/blob/master/config.xml | \
    java -jar jenkins-cli.jar -s http://localhost:8080/jenkins create-job symfony2-php-template
    or add the template manually:
    cd $JENKINS_HOME/jobs
    mkdir symfony2-php-template
    cd symfony2-php-template
    wget https://github.com/xurumelous/symfony2-jenkins-template/blob/master/config.xml
    cd ..
    chown -R jenkins:jenkins symfony2-php-template/

  3. reload the Jenkins configuration, for example using the Jenkins CLI:
    java -jar jenkins-cli.jar -s http://localhost:8080 reload-configuration

  4. click on “New Job”;
  5. enter “Job name”;
  6. select “Copy existing job” and type “ symfony2-php-template ” in the “Copy from” field;
  7. click “OK”;
  8. configure version control in your new project and other necessary fields / modules.


Project configuration and troubleshooting


  1. Change the standard Jenkins-PHP config according to Symfony2-Jenkins-PHP, as described here - github.com/xurumelous/symfony2-jenkins-template :
    • move the folder with Jenkins to [SYMFONY2_ROOT] / app / Resources / inside your Symfony2 project;
    • move the build.xml file to the root of your Symfony2 application;
    • move the phpunit.xml file to the [SYMFONY2_ROOT] / app folder or update the existing file. The logging node is necessary if you want to profile and log unit testing reports;

  2. if you get the error "PHP Fatal error: Class 'XSLTProcessor' not found in /usr/share/php/TheSeer/fXSL/fxsltprocessor.php on line 58 ", you can fix it as follows:
    sudo apt-get install php5-xsl
  3. you may also get the error " PHP Warning: require (/ var / lib / jenkins / jobs / TestJob / workspace / app /../ vendor / autoload.php): failed to open stream: No such file or directory in / var / lib / jenkins / jobs / TestJob / workspace / app / autoload.php on line 5 "because we use symfony v2.1 which composer blows . You can eliminate it in the following way:
    • add composer step to your build.xml . How to do this is described in this article ;
    • if you continue to receive this message after adding the composer step , you may need to add a dependency for PHPunit on composer : depends = ”composer” ;

  4. Sometimes you may have a problem in the “vendors” step , in which you will see something like:
    [exec] The deps file is not valid ini syntax. Perhaps missing a trailing newline?
    [exec] PHP Warning:  parse_ini_file(/var/lib/jenkins/jobs/TestJob/workspace/deps): failed to open stream: No such file or directory in  /var/lib/jenkins/jobs/TestJob/workspace/bin/vendors on line 69
    You can fix this by removing vendors from the build dependency and the vendors target block in the build.xml script
  5. if you get the result Status: 2 during the execution of the codesniffer step (phpcs), you need to set Symfony2 the encoding standard that can be taken on this resource ;
  6. enable the “Poll SCM” option and write below: * / 5 * * * * (by enabling this option you instruct Jenkins to check the project repository every 5 minutes for new commits. If changes (commits) are found, Jenkins will automatically start the build project).


It's all! You are now ready to build your PHP Symfony2 project using Jenkins! If you find any errors (or corrections), useful links, or if you have other suggestions, leave comments here or in the original article.

Enjoy the result!

Also popular now: