This configuration works successfully with Symfony ver. 2.1 and Jenkins ver. 1.480.1.
Using the Symfony2 PHP Jenkins job template
I based the first steps on http://jenkins-php.org/, but I will use
phpunit.xml and additional files from this website: https://github.com/xurumelous/symfony2-jenkins-template.
- Fetch the jenkins-cli.jar from your Jenkins server
- 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/
- Reload Jenkins’ configuration, for instance using the Jenkins CLI:
java -jar jenkins-cli.jar -s http://localhost:8080 reload-configuration
- Click on “New Job”
- Enter the “Job name”
- Select “Copy existing job” and enter “symfony2-php-template” into the “Copy from” field.
- Click “OK”
- Configure your new job with version control and whatever other fields you need.
Project configuring and issues fixing
- 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
build.xmlto the root folder of your Symfony2 application
[SYMFONY2_ROOT]/appfolder or update the existing one. The
loggingnode is needed!
- Move the Jenkins folder to
- 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
- 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:
- Add the composer step into a build.xml http://testonsteroid.tumblr.com/post/20815956422/jenkins-php-template-on-the-edge.
- If you still receive the error message after adding the composer step, you might need to add a dependency for PHPunit on composer: depends=”composer”.
- 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
- 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
- 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!