For the past weeks I’ve wrote a series of articles on how to create a continuous integration server which began with the article Tools for a Continuous Integration (CI) server for PHP projects.

You can automate much more than what I’ve shown in this series of articles, specially front-end processes or automated tests and I hope you got to a point where you can investigate and start to tweak the continuous integration process to match your needs.

Without further ado, check how you can integrate the tools.

  1. Add SonarQube analysis to TeamCity build
  2. Integrate SonarQube and Redmine

1. Add SonarQube analysis to TeamCity build

In the article Install and configure TeamCity 9 I showed how to install and configure a continuous integration server. At the time we added two steps to the build: one to execute the Gulp task and the other to execute Composer. Now, I’ll show you how to expand that build configuration to execute PHPUnit tests and SonarQube’s analysis.

As a requirement you need to have TeamCity and SonarQube installed. If you want to install them check the following articles:

Follow the steps to integrate SonarQube analysis with TeamCity.

  1. Go to the Projects page on TeamCity and click on the arrow next to your project’s name to expand the menu. Afterwards click on Edit Settings.

    Integrate SonarQube with TeamCity and Redmine images/15-integrate-sonarqube-with-teamcity-and-redmine/263-teamcity-edit-project-settings.png
  2. Click the Build Steps separator and then click on the Add build step button. You will create two steps (or just one, with both commands) where Runner Type is Command Line and Run is Custom Script. Here’s the commands you should enter:

    phpunit
    /opt/sonar-runner-2.4/bin/sonar-runner -e -X
    

    Integrate SonarQube with TeamCity and Redmine images/15-integrate-sonarqube-with-teamcity-and-redmine/261-teamcity-add-phpunit-step.png
    Integrate SonarQube with TeamCity and Redmine images/15-integrate-sonarqube-with-teamcity-and-redmine/262-teamcity-add-sonarqube-runner-step.png

    And you’re done. Whenever you push changes to the Git repository the tests will be executed and then a SonarQube analysis is performed. This means you can have an history of your project’s quality as you go.

2. Integrate SonarQube and Redmine

In the article Install Redmine and integrate it with Git I’ve shown how to install and configure Redmine, a project management application. You may want to create some technical issues related to the quality of your application and, if so, it can be handy to create those issues automatically through SonarQube.

In the following steps I’ll show you how to integrate SonarQube with Redmine so you can create Redmine tasks through SonarQube.

  1. On SonarQube go to Settings » Redmine and fill the Redmine URL field.

    Integrate SonarQube with TeamCity and Redmine images/15-integrate-sonarqube-with-teamcity-and-redmine/258-sonarqube-global-redmine-settings.png
    If you don't see Redmine most likely you haven't installed the plugin. To do so go to Settings » System » Update Center. Click the Available plugins tab and find Redmine (within Integration group) and install it.
  2. Go to Redmine at the page Administration » Settings and enable the Enable REST web service option.

    Integrate SonarQube with TeamCity and Redmine images/15-integrate-sonarqube-with-teamcity-and-redmine/256-redmine-enable-rest-api.png
  3. While in Redmine go to the My Account page and look for the section API access key on the side bar. Click the show link and copy the given key.

    Integrate SonarQube with TeamCity and Redmine images/15-integrate-sonarqube-with-teamcity-and-redmine/255-redmine-api-acccess-key.png
  4. Back to SonarQube go to Dashboard and click on your project’s name. Then go to Settings » Redmine and fill the previously coppied key. You should also fill Redmine’s project identifier so SonarQube can correctly create the issues on the correct project.

    Click on the Connect button to make sure your settings are correct. Assuming they are, fill the Priority and Tracker fields (they will be used when creating a new issue) and click on the Save Settings button.

    Integrate SonarQube with TeamCity and Redmine images/15-integrate-sonarqube-with-teamcity-and-redmine/260-sonarqube-redmine-project-settings.png
  5. Now when you navigate to any issue you’ll be able to create a new Redmine issue through the menu More » Redmine.

    Integrate SonarQube with TeamCity and Redmine images/15-integrate-sonarqube-with-teamcity-and-redmine/259-sonarqube-link-to-redmine.png
  6. You can confirm the issue was correctly create when you log into Redmine:

    Integrate SonarQube with TeamCity and Redmine images/15-integrate-sonarqube-with-teamcity-and-redmine/257-redmine-view-task-created-sonarqube.png

An so we end this series of articles. I hope you enjoyed it and if you have any troubles please do leave a comment..

This article is a part of the series How to set up a Continuous Integration Server for PHP projects

  1. Tools for a Continuous Integration (CI) server for PHP projects
  2. Install SSH and Git on Linux and configure a Windows development machine
  3. Install Redmine and integrate it with Git
  4. Install and configure TeamCity 9
  5. Install and configure TeamCity Agent on Linux Mint
  6. Install SonarQube and SonarQube Runner on Linux Mint
  7. Analyse a Laravel 5 (PHP) project with SonarQube
  8. Integrate SonarQube with TeamCity and Redmine - You are here