modess.io - Jenkins & PHP, continuous integration tutorial









Search Preview

Jenkins & PHP, continuous integration tutorial | modess.io

modess.io
Get up and running with Jenkins & PHP for continuous integration of your application, to improve code quality and the health of your code.
.io > modess.io

SEO audit: Content analysis

Language Error! No language localisation is found.
Title Jenkins & PHP, continuous integration tutorial | modess.io
Text / HTML ratio 60 %
Frame Excellent! The website does not use iFrame solutions.
Flash Excellent! The website does not have any flash contents.
Keywords cloud Jenkins code PHP project sudo install tools continuous integration tests running repository job Laravel jenkins CI metrics set \ build
Keywords consistency
Keyword Content Title Description Headings
Jenkins 31
code 27
PHP 25
project 13
sudo 13
install 13
Headings
H1 H2 H3 H4 H5 H6
2 12 19 0 0 0
Images We found 11 images on this web page.

SEO Keywords (Single)

Keyword Occurrence Density
Jenkins 31 1.55 %
code 27 1.35 %
PHP 25 1.25 %
project 13 0.65 %
sudo 13 0.65 %
install 13 0.65 %
tools 11 0.55 %
continuous 10 0.50 %
integration 10 0.50 %
tests 10 0.50 %
running 10 0.50 %
repository 9 0.45 %
job 9 0.45 %
Laravel 8 0.40 %
jenkins 8 0.40 %
CI 8 0.40 %
metrics 8 0.40 %
set 8 0.40 %
\ 7 0.35 %
build 7 0.35 %

SEO Keywords (Two Word)

Keyword Occurrence Density
Jenkins PHP 10 0.50 %
continuous integration 9 0.45 %
your code 8 0.40 %
of your 7 0.35 %
in the 7 0.35 %
your project 7 0.35 %
to the 6 0.30 %
in your 6 0.30 %
you have 6 0.30 %
code style 5 0.25 %
need to 5 0.25 %
we need 5 0.25 %
that is 5 0.25 %
I have 5 0.25 %
up and 4 0.20 %
sudo aptget 4 0.20 %
to use 4 0.20 %
that you 4 0.20 %
to install 4 0.20 %
want to 4 0.20 %

SEO Keywords (Three Word)

Keyword Occurrence Density Possible Spam
Jenkins PHP continuous 3 0.15 % No
for your project 3 0.15 % No
username JCLIUSER password 3 0.15 % No
jenkinsclijar s httplocalhost8080 3 0.15 % No
jar jenkinsclijar s 3 0.15 % No
java jar jenkinsclijar 3 0.15 % No
of your code 3 0.15 % No
I have a 3 0.15 % No
JCLIUSER password JCLIPASS 3 0.15 % No
the CLI tool 3 0.15 % No
to use the 3 0.15 % No
be able to 3 0.15 % No
up and running 3 0.15 % No
in your project 3 0.15 % No
you don’t have 2 0.10 % No
in general I’m 2 0.10 % No
I write mostly 2 0.10 % No
write mostly on 2 0.10 % No
on deployment continuous 2 0.10 % No
deployment continuous integration 2 0.10 % No

SEO Keywords (Four Word)

Keyword Occurrence Density Possible Spam
java jar jenkinsclijar s 3 0.15 % No
jar jenkinsclijar s httplocalhost8080 3 0.15 % No
username JCLIUSER password JCLIPASS 3 0.15 % No
Jenkins PHP continuous integration 2 0.10 % No
author of Deploying PHP 2 0.10 % No
continuous integration Laravel and 2 0.10 % No
integration Laravel and PHP 2 0.10 % No
Laravel and PHP in 2 0.10 % No
and PHP in general 2 0.10 % No
PHP in general I’m 2 0.10 % No
general I’m the author 2 0.10 % No
I’m the author of 2 0.10 % No
the author of Deploying 2 0.10 % No
PHP Applications and organizer 2 0.10 % No
of Deploying PHP Applications 2 0.10 % No
Deploying PHP Applications and 2 0.10 % No
on deployment continuous integration 2 0.10 % No
Applications and organizer of 2 0.10 % No
and organizer of Laravel 2 0.10 % No
organizer of Laravel Stockholm 2 0.10 % No

Internal links in - modess.io

continuous integration for Laravel with Jenkins
Laravel & Jenkins: Continuous integration | modess.io
Jenkins & PHP, continuous integration tutorial
Jenkins & PHP, continuous integration tutorial | modess.io
Simple pagination in PHP with the Laravel pagination package
Simple pagination in PHP with the Laravel pagination package | modess.io
PHP micro framework for your REST API – Part 1: Selection
PHP micro framework for your REST API – Part 1: Selection | modess.io
Possible benefits of meditation for developers
Possible benefits of meditation for developers | modess.io
One year of working remote
One year of working remote | modess.io
Older
Blog | modess.io
Talks
Talks | modess.io
Email
Email Protection | Cloudflare

Modess.io Spined HTML


Jenkins & PHP, continuous integration tutorial | modess.io Jump to: Navigation Jenkins & PHP, continuous integration tutorial 08 Sep 2016 Get up and running with Jenkins & PHP for continuous integration of your application, to modernize lawmaking quality and the health of your code.A while ago I wrote a blog post on setting up continuous integration for Laravel with Jenkins. That was for Laravel 4, and many things have happened since. In this post I widen the telescopic and aim for continuous integration (CI) for PHP applications in general. Applications are looking increasingly and increasingly similar to one flipside in terms of structure and tooling, which allows for a increasingly unstipulated tideway to them. Jenkins & PHP work perfectly together and Jenkins is a unconfined tool if you want full tenancy of your CI process since everything is unshut source and it has a huge and zippy community.Jenkins is an unshut source continuous integration server that is a swiss unwashed knife. CI is the process of performing static lawmaking analyses and running tests for an using on a regular basis, often on a push to a repository. Jenkins will poll that repository for changes and as soon as anything happens it will pull lanugo the changes and perform all specified tasks. It’s moreover possible to indulge Jenkins to listen to incoming webhooks for triggering updates. The kind of wringer to be performed is up to each application, but often you squint for errors, run tests, run static wringer tools and then have Jenkins generate a nice visual report for looking at the results.Once you have everything up and running you can sit when and relax, but surpassing that you need to do some configuration and it can be quite complex. Configuration is mostly washed-up in XML and that is never fun to deal with. I’ll guide you through this process in this post and provide you with some lawmaking that you can reuse in your project. I want to requite a big shout out to the project that I have used as a reference for this tutorial, with slight modifications to it, and that is http://jenkins-php.org.For this tutorial I will set up a Jenkins job for CI on the Zend Expressive framework, instead of a Laravel application. I have a fork of the framework on Github, where I have widow the necessary files for the CI process (explanation unelevated how you do that in your own repository), which Jenkins will poll for changes and build. In this tutorial I’ll be installing Jenkins on a machine running Ubuntu 14.04.Why superintendency well-nigh Jenkins & PHP continuous integration?Code qualityEvery other treatise for CI ends up in this category. Delivering upper quality software is not an easy task, and CI is one of the weightier tools for helping you in achieving that. It makes sure to run the tests and generate reports for lawmaking coverage.Moreoverit performs static wringer on your lawmaking and provide you with visual reports for it. This provides you with solid metrics well-nigh the health of your code.AutomationWhen running tests automatically on every push, you don’t have the issue of tests not stuff run surpassing a deploy considering of human error. You could automate your whole deployment process if you’d like to as well.Find bugs fasterSince you are doing continuous integration, you don’t have to worry well-nigh a long integration period later. You can reservation bugs older in the process and prioritize fixing them surpassing they rationalization any problems. It isn’t some magic silver bullet for getting rid of bugs, but it allows you to react to them faster.Developer confidenceWhen you know that tests are stuff run on each push, you proceeds conviction in your lawmaking since you will know if your new lawmaking breaks any tests. Or it could be as easy as your lawmaking not passing the linter.Reduces the release cycleYou increase conviction when you make sure that builds pass all tests you have automated, which allows for increasingly efficient deployment. The loftiness between your local environment and your production environment decreases.Visibility and communicationWith a process that is unshut to everyone, you and your team will be worldly-wise to see what is going on and communicate well-nigh it with increasingly ease. And with higher transparency comes the goody of less dumbo domain knowledge on some “experts”, and hopefully spread the domain knowledge increasingly plane between team members.Team prideCall this what you will, but I like the term team pride. When you unzip a culture of pride for good quality lawmaking in your team, you’ve come a long way. I’m not talking well-nigh pride as in “I wrote this code, don’t fuck with it”, I’m talking well-nigh “I wrote this code, it has tests, is well documented, well decoupled and does not unravel the build. Let’s discuss remoter improvements on it”. Gathering as a team virtually lawmaking quality, taking pride in increasing the trend of lawmaking coverage and decreasing the lawmaking style violations is a powerful mentality.Preparing your applicationYou need to add some configuration files and a build directory to your repository. These can be found in my php-jenkins repository. Follow the instructions setup there, it’s only well-nigh subtracting some files to your project and possibly waffly some paths in them.Installing JenkinsWe’ll add the Jenkins repository, install Jenkins and a few other dependencies.wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add - sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' sudo apt-get update sudo apt-get install -y jenkins ant git-core flourish unzip If the installation says it encountered any errors, just start the service manuallysudo service jenkins start Wait for a while to let it marching up, and then go to the URL of your server with port 8080. I have a Vagrant machine with a host named jenkins so I’m using http://jenkins:8080. It will prompt you for the initial admin password it has generated for you. Retrieve it withsudo cat /var/lib/jenkins/secrets/initialAdminPassword After that you may skip the getting started guide and view Jenkins in all its glory.Switch over to the user jenkins that have been created. From now on we’ll run most commands as this user. This is to make sure that everything works for when we’re making builds later on since this is the user that Jenkins uses.sudo su jenkins Let’s moreover save the user and password for when we’re going to use the CLI tool.echo 'JCLIUSER=admin' >> ~/.bashrc reverberate 'JCLIPASS=<YOUR_PASSWORD>' >> ~/.bashrc source ~/.bashrc Security settingsNow we need to fix a security setting to be worldly-wise to use the CLI tool. Go to Manage Jenkins, then Configure Global Security. You’ll find TCP port for JNLP teachers that is set to disabled. Click Fixed and set any port you’d like, 8088 for example. While you’re there, moreover set the markup formatter to Safe HTML so we can exhibit images in our project description. Then hit Apply. Warning, do not hit Save here! For some reason it throws an error for me when hitting save instead of apply.Install pluginsLet’s install the plugins we need for making Jenkins & PHP play nice together. And in order to do that we first need to download the CLI tool.wget http://localhost:8080/jnlpJars/jenkins-cli.jar java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin \ checkstyle cloverphp crap4j dry htmlpublisher jdepend \ plot pmd violations warnings xunit git greenballs \ --username $JCLIUSER --password $JCLIPASS java -jar jenkins-cli.jar -s http://localhost:8080 safe-restart --username $JCLIUSER --password $JCLIPASS This will moreover install the plugin to exhibit untried balls on passing builds instead of undecorous ones. Why they’re undecorous from the start is considering of Japanese culture where you say you have a undecorous light instead of untried when driving in traffic, and the original tragedian of Jenkins grew up there. Quite fascinating. :)Installing PHP, Composer and toolsIn order to unzip CI with Jenkins & PHP, we of undertow need PHP installed. Exit from the jenkins user, install PHP7.0 and some extensions that are required. Which PHP version you segregate to install is up to you and your application’s needs. I tend to use PHP7.0 when I can considering of the performance improvements. To install PHP5.4, replace all instances of php7.0 with php5 in the pursuit commands. Or to install PHP5.6, replace all instances of php7.0 with php5.6.exit sudo LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php sudo apt-get update sudo apt-get install -y php7.0 php7.0-xdebug php7.0-xsl php7.0-dom \ php7.0-zip php7.0-mbstring Installing ComposerIn my last post we used PEAR to install the tools we needed, but this time we’ll use Composer instead to install them at the global level. So first we install Composer.php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer php -r "unlink('composer-setup.php');" sudo chown -R $USER:$USER ~/.composer/ Installing toolsNow switch when to the jenkins user and install all tools we need.sudo su jenkins composer global config minimum-stability dev composer global config prefer-stable true composer global require phpunit/phpunit squizlabs/php_codesniffer \ phploc/phploc pdepend/pdepend phpmd/phpmd sebastian/phpcpd \ mayflower/php-codebrowser theseer/phpdox:dev-master These are all the tools we need for running our tasks, however Jenkins will not be worldly-wise to find them when running our builds. We need to add the composer directories to PATH. Go to Manage Jenkins, then go to Configure System. Under Global properties, click the trammels box for Environment variables and set the name to PATH and the value to $PATH:vendor/bin:/var/lib/jenkins/.config/composer/vendor/bin, then save_._ This ensures that Jenkins tries to use the project’s local dependencies first, then fall when on your global packages.Zaher Ghaibeh pointed out in the comments that on Ubuntu 16 with PHP7, the value should be set to $PATH:vendor/bin:/var/lib/jenkins/.composer/vendor/bin/ instead.The toolsIn total we installed eight tools through composer, let’s go through them one by one to requite you a unstipulated overview on the metrics they will provide. Without these tools there is no goody of Jenkins & PHP together, since they provide all data necessary for our builds.PHPUnitThis one I don’t think I really have to explain, it is responsible of running our unit tests and generate lawmaking coverage.PHP_CodeSniffer (phpcs)Detects violations of a specific lawmaking style. The debate well-nigh whether we should plane use a lawmaking style is a heated one, but I think it’s a good idea and I don’t have time to explain why here. Configuration files I provided for this tool uses the PSR-2 lawmaking style, probably the most widespread lawmaking style within the PHP community.phplocNumber of lines of code, number of classes, number of interfaces, etc. Nothing fancy, pretty straightforward metrics well-nigh your code. Do what you wish with it. What could be interesting is if your lawmaking is depending on global stuff, might be a lawmaking smell.pdependThis tool shows you the quality of your diamond in the terms of extensibility, reusability and maintainability. – The projectThis provides some very wide metrics for your project. If you want to swoop deeper I suggest going to the documentation for the software metrics.PHPMD – PHP Mess DetectorThis provides some very good metrics of your lawmaking quality. I have a blog post explaining the metrics: NPath complexity and cyclomatic complexity explained.PHP Copy/Paste Detector (phpcpd)Just as the name suggests, it tries to determine where you have duplicated lawmaking in your project.PHP_CodeBrowser (phpcb)Generates a browsable output for your project files. If you have washed-up a good job of using phpdoc in your project, this will requite you some good value.phpDoxGenerates API documentation for your project.Setting up the build projectWe now need a job for our Jenkins & PHP project. This we’ll do by subtracting a vanilla job that we’ll use as a wiring for the job. Once we have everything set up you may remove it if you want to.curl -L https://raw.githubusercontent.com/modess/php-jenkins-template/master/config.xml | \ java -jar jenkins-cli.jar -s http://localhost:8080 create-job php-template --username $JCLIUSER --password $JCLIPASS Refresh the home location for Jenkins and you should see a disabled job named php-template. It contains all the configuration for running tools, parsing output and processing it to a format that Jenkins can display.We’ll use this template by duplicating and customizing it for our application’s job. Start by clicking New Item in the left side menu.Fill in the name of the project and segregate to reprinting from the template job.Click OK to continue.We want to poll our git repository for changes so it makes a new build on each push. I’ll use my fork of Zend Expressive (https://github.com/modess/zend-expressive-jenkins.git) with the build files committed.Add the polling every minute (* * * * *), don’t worry well-nigh the warning. A largest solution for this would be to listen to a webhook when changes are pushed to the repository, but that might be a separate post.Hit Save, and that’s all we need. Enable the job and it will perform the first build (once it polls the repository), hopefully it will be a successful one.What now?Now that you have Jenkins & PHP set up and running, I suggest you click virtually in the interface and get familiar with it.Squintat the metrics provided for you and try to get a finger of what they tell you and why you should try and modernize them. AboutHi! My name is Niklas Modess and I’m a PHP developer from Stockholm, Sweden. I write mostly on deployment, continuous integration, Laravel and PHP in general. I’m the tragedian of Deploying PHP Applications and organizer of Laravel Stockholm. Social: Twitter GitHub Email Stack Overflow LinkedIn Related Posts Simple pagination in PHP with the Laravel pagination package 10 Feb 2016 PHP micro framework for your REST API – Part 1: Selection 07 Jan 2016 Possible benefits of meditation for developers 26 Sep 2015CommentsPlease enable JavaScript to view the comments powered by Disqus.© 2018. All rights reserved. Powered by Hydejack v7.5.0modess.io Hi! My name is Niklas Modess and I’m a PHP developer from Stockholm, Sweden. I write mostly on deployment, continuous integration, Laravel and PHP in general. I’m the tragedian of Deploying PHP Applications and organizer of Laravel Stockholm. Navigation: Talks Social: Twitter GitHub Email Stack Overflow LinkedIn Templates (for web app): Loading… Error Sorry, an error occurred while loading .WhenPermalink