Hello. With this post I would like to launch a series of guides, which show you how to configure TeamCity integration for projects written in PHP. This server is not too often used to integrate such projects – it is very difficult to find descriptions of how to integrate the various, frequently used tools. The reason is probably lack of „direct” integration with PHPUnit, Selenium, etc. But all these tools use standard log files on with proper configuration it works very well.

I will split this guide into the following sections and publish them in a short periods of time:

1. Basic configuration – an introduction to TeamCity
2. Integration with PHPUnit – Unit Tests
3. Integration with phpDocumentor DocBlox- Generate project documentation
4. Integration with PHP Copy & Paste detector – detection of code duplication
5. Integration with PHP Mess Detector – code analysis in terms of potential performance problems and errors
6. Integration with PHP Depend – code analysis in terms of its complexity
7. Integration with the PHP Code Sniffer – a tool for verifying the correctness / behavioral coding standards
8. Integration with phploc – a tool for counting lines of code
9. Integration with PHP Dead Code Detector – a tool for the detection of unused code
10. Integration with Selenium-RC
11. Integration of unit tests for JavaScript

This guide is based largely on post Continuous Integration and TeamCity (??????????? ?????????? ? TeamCity) and the topic in a forum Integrate code coverage report (clover format, PHPUnit).

The list is extensive, but some sections will be very simple and should not take more than a few minutes.

So it’s time to start:)


Server Installation can be done in two ways: either as a standalone server or as an application running on an existing instance of Tomcat. I will describe the first method, because I do not use Tomcat for any projects. The second method of installation is described in detail in a very good documentation.

After entering the Download page You must select the operating system and download the latest version.

Free Edition allows you to save up to 20 configuration, the user also has a limit of 20, and is not possible to authenticate users via external systems (eg LDAP, Active Directory). It also allows the installation of only three agents – but this is the limit for the paid version – each additional agent for a moderate expenditure of 200 + dollars, but three are sufficient completely to start with.

After downloading the package to the hard simply issue the command:

tar xfz TeamCity-6.0.2.tar.gz

This will create a directory containing the server. When you go to the bin, simply run the command:

./runAll.sh start

This will start the server and an agent. The whole administration is done through a convenient web interface available at http://web_server_host:8111/.

After accepting the license, the server prompts for creating a user who is administrator.

Creating project

Now it is time to create a first project

Maybe now the word about the purpose of preparing the building configuration. They can be divided in different ways and differently named, but it seems to me that there are two main expected results of automation.

  1. New version
    This configuration is designed to release a new version – the production, to test the demo etc etc. We are interested in downloading the latest version of the directory on a particular server – so that you can open the project in the browser.
  2. Tests
    This configuration provides automatic tests, it takes quite long to complete, but its purpose is not always the release version that you can click – is not required for a specified server or the specified location.

It is well known, has fairly good documentation and integrates great with TeamCity. Both configurations can be based on the same file – they differ only in target – the second case also contains a call to download the new version.

Before adding a specific configuration, you must add code repository. Just click on the „VCS Roots” and then on the „Create New VCS Root.” After assigning a name, select the repository type, select options for handling external repositories and share new configurations of the new projects.

After adding the repository and returning to the first tab, you can begin adding the specific build configurations.

On this page we give the standard information that does not require explanation – except for two: Artifacts path (1) and „Status widget” (2).

The first allows you to automatically import all kinds of reports that will be generated by tests and other tools. You can, for example, set the output directory of PHP Documentator. I prepare all my configurations so that the results of all the tools are stored in separate subdirectories, and here I give a path to the root directory. This allows you to view everything that is generated.

The second option allows you to download the status of the last status via JavaScript or an image of a certain color this allows you to place it in footer on test server. For more details and code examples, see the documentation.

When you click the „VCS Settings>>>” at the bottom of the page you will be asked to choose a code repository.

On this screen, the most important are two options marked in red. Here is the first difference in the configuration. If you want to prepare a version available to click, then choose the first option „Do not checkout files automatically” – this means that the agent will not download new code when it detects changes on the disk – for example, configuration. You will have to prepare first checkout by yourself. In this case, you must also specify the directory where you will download the code – probably accessible by the web server.

If you want to just test the code (automatically – by the unit tests – Selenium is a special case of which I write for in a moment) it does not matter where code will be download – it will run from the command line, and the results will be imported to the server. This allow you to install additional build agents on several servers (just make sure to install all the tools) and to enable to build and test more configurations at the same time. „Automatic download on server” will download new version, archive it and send the agent. It is also possible to download directly to the agent – in this case you need a version control client on machines with an agents.

Selenium is a special case – the checkout of code should be on specific server. In this case, choose to automatically download on the agent and to the specified directory. To select specific agent I use „Build agent requirements” from project settings – and make sure that the agent has the property: „Selenium” :) In this way, I do not need to prepare the configuration and directory – the agent will take care of this, and I can prepare more than one agent to perform the tests.

At the bottom of the page just click „Add Build Step>>>” to move on to adding the steps of building.

Since version 6.0, TeamCity allows you to add a different steps.Now you can make a build.xml file with different targets and select them according to your needs. The basic version includes and build file with the target: „checkout”.

<?xml version="1.0" encoding="UTF-8"?>
<project name="Application" default="checkout">

    <property name="artifactsDir" value="${basedir}/tests/artifacts/" description="Base dir for all output of build commands"/>

    <target name="checkout" description="Base task - update directory with new version from server and overwrite all conflicts with files from server">
        <exec executable="svn" failonerror="true" output="${artifactsDir}/svn.log">

            <arg value="up"/>
            <arg value="--force"/>
            <arg value="--accept theirs-full"/>



Save the above is to a file named build.xml in the root directory of the project.

And that’s about it. The system should now be able to get the code to the appropriate directory and the status should be green:)

Now, in the configuration of a project, on the tab „Settings” just add a „Build Trigger”, set every hour or every day at 12 and the system will automatically update the versions.

In the next post: integration with unit tests.

6 lutego 2011 14:56 Grzegorz Drozd Brak komentarzy Komentuj Kategorie: Narz?dzia, PHP, Praca, TeamCity

Bądź uprzejma(y).

Możesz używać następujących tagów HTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Twój adres e-mail nie będzie wyświetlony.

Twój adres e-mail nie będzie przekazany nikomu.

Wszystkie komentarze są moderowane.