Archives
Visitors
  • 50335This month:
  • 365Today:
  • 17Currently online:



LeaseWeb CDN

Continuous Integration for Symfony2 using Jenkins

Today I will show how to set up Continuous Integration (CI) for Symfony2 using Jenkins and the PHP-template for Jenkins jobs by Sebastian Bergmann.

This configuration works successfully with Symfony ver. 2.1 and Jenkins ver. 1.480.1.

Installing requirements

Before creating template jobs you need to install the Required Jenkins Plugins and Required PHP Tools.

Using the Symfony2 PHP Jenkins job template

I based the first steps on http://jenkins-php.org/, but I will use config.xml, build.xml, phpunit.xml and additional files from this website: https://github.com/xurumelous/symfony2-jenkins-template.

  1. Fetch the jenkins-cli.jar from your Jenkins server
    wget http://localhost:8080/jnlpJars/jenkins-cli.jar
  2. Download and install the job 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 Jenkins’ configuration, for instance using the Jenkins CLI:
    java -jar jenkins-cli.jar -s http://localhost:8080 reload-configuration
  4. Click on “New Job”
  5. Enter the “Job name”
  6. Select “Copy existing job” and enter “symfony2-php-template” into the “Copy from” field.
  7. Click “OK”
  8. Configure your new job with version control and whatever other fields you need.

Project configuring and issues fixing

  1. Make changes from the basic Jenkins-PHP config to Symfony2-Jenkins-PHP as described here: https://github.com/xurumelous/symfony2-jenkins-template
    • Move the Jenkins folder to [SYMFONY2_ROOT]/app/Resources/ inside your Symfony2 project
    • Move build.xml to the root folder of your Symfony2 application
    • Move phpunit.xml to [SYMFONY2_ROOT]/app folder or update the existing one. The logging node is needed!
  2. If you get the following message: PHP Fatal error:  Class ‘XSLTProcessor’ not found in /usr/share/php/TheSeer/fXSL/fxsltprocessor.php on line 58, you can fix  it with 
    sudo apt-get install php5-xsl
  3. You might also get this error message, because we run Symfony 2.1, which needs a composer: 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 . You can fix this problem like this:
  4. Sometimes you encounter a problem on the “vendors” step, saying something like this:

    [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 build dependency and the “vendors” target in build.xml

  5. If you get a Status: 2 during the codesniffer step (phpcs) you need to install Symfony2 coding standard https://github.com/opensky/Symfony2-coding-standard
  6. Enable checkbox “Poll SCM” and write: */5 * * * * (This step makes Jenkins check every 5 minutes if there are changes in the repository. If any changes are found, it will automatically build a project)

That’s it! You are now ready to build your PHP Symfony2 project with Jenkins! If you find bugs (or fixes), links, or have other suggestions, do not hesitate to comment below.

Enjoy the result!

Leave a Reply