TeamCity quick start guide
In this topic: |
TeamCity is a commercial build server application that provides continuous integration, reporting, and parallel software builds. You can integrate your Klocwork analysis build with a TeamCity server to combine each of these features with your Klocwork analysis.
This example assumes that you have already created a TeamCity project and that you may or may not have active build configurations.
Each TeamCity build configuration defines the settings for your build. This includes the build step, which defines the build runner type, along with build file path information, project information, build triggers, failure conditions and build parameters. For more information about creating your build configuration, refer to the TeamCity documentation.
Create your project/build configuration
If you haven't already, create your project in TeamCity. Next, create your build configuration as you normally would, taking care to specify the details of your build. Then, as part of your build configuration, you must perform the following step:
- In the left panel, click Version Control Settings, then under Checkout Options, select Automatically on agent (if supported by VCS roots) from the VCS checkout mode drop-down.
Enable Klocwork Static Analysis on your project
TeamCity uses build agents to perform build operations. You can use multiple build agents to perform many builds in parallel. The build agent typically checks out the source code, initializes the build environment, and runs the software build. You must configure each build agent that will be used to perform Klocwork analysis. The Klocwork Static Analysis build step automatically wraps your existing build steps with the necessary commands to run analysis. The analysis step itself has an option to ignore build steps if you do not want those steps included.
- In TeamCity, access your projects list and select the project you want to configure. From here, click Edit Settings
- Click Build Steps
- Click the Add Build Step button and choose Klocwork Static Analysis as the runner type.
- Fill in the Klocwork Server information. The server doesn't have to be on the local machine. The Klocwork Server needs to be specified for the build configuration. It contacts the Klocwork Server to obtain the project configuration for analysis.
- Next, click Authorize and log in as any user who is able to view the project. The project needs to exist on both the TeamCity server and on the Klocwork Server. If the project name differs, specify this here as well.
- Next you can set up any relevant build failure conditions. You can configure the build to fail if the static analysis is incomplete or create a regular expression to capture any number of failure scenarios. By default, the CI build will fail if any issues are detected. Below is an image which shows the fully configured build step:
You can synchronize custom checkers from your server to your TeamCity build agents by using kwdeploy. The kwdeploy executable can be found on your build agents in the following location: <teamcity_build_agent_root>\tools\klocwork\<platform>\bin\kwdeploy.exe
For example:
<teamcity_build_agent_root>\tools\klocwork\windows\bin\kwdeploy sync --url http(s)://<Klocwork_host>:<port>
Enable build failure
If you want your builds to fail when any new defects are found, you can add a build parameter in TeamCity that will mark a build as failed if defects are discovered during analysis. The following image shows an example of TeamCity configured to fail the build if the JSON file includes one or more new issues. The detected issues will include any new issues since the last build and the issues from all failed builds since the last successful build. If you choose not to fail the build, then the issue list will contain only the issues detected in the latest build.

Run a build and verify the results in Klocwork
You can verify your integration by running a build and checking the JSON output in TeamCity:- The IDE must be started already
- The Klocwork desktop analysis plug-in must be installed
- The relevant project must be open
- The file containing the issue cannot be modified since the last analysis