Qodana 2023.1 Help

TeamCity

Starting from 2022.04, Qodana functionality is available in TeamCity by default. To start using it, these prerequisites need to be met:

  • You use TeamCity as a build server for your project. If not, learn how to do it in TeamCity documentation.

  • Your project language is included in the list of fully supported technologies.

  • If you use your own TeamCity agents, make sure that Docker is installed on the agent machines and accessible by the users TeamCity is running under. TeamCity agents hosted by JetBrains already meet this condition.

Add a Qodana runner

Assuming that you have already created your project and configured your build, follow the steps below.

  1. Navigate to your build configuration.

    Navigating to the build configuration

  2. On the build configuration page, select Build Steps from the Edit configuration list.

    Navigating to the step configuration

  3. On the Build steps page, click the Add build step button.

    Creating a new build step

  4. From the Runner type list, select Qodana as a runner. On the New Build Step page, you can configure the Qodana runner using the basic options. Otherwise, click Show advanced options to expand the list of configuration options.

    Expanding all configuration options of the Qodana runner

  5. Fill in the fields using this description.

    Step name uniquely identifies this step among other build steps.

    Execute step configures the build condition that will trigger this build step.

    Working directory sets the directory for the build process. For more information, see the TeamCity documentation. You can leave this field empty if the Checkout directory parameter is specified on the Version Control Settings tab.

    Report ID uniquely identifies the report to let you distinguish between multiple reports when several inspection steps are configured within a single build.

    The Forward reports to TeamCity tests checkbox configures Qodana report availability in the Test tab of TeamCity UI. Using this option, you can overview codebase problems along with other problems detected.

    Linter configures the Qodana Linter.

    Version is by default set to Latest.

    Inspection profile defines the inspection profile. For more information, see the Configure profile section. The available values are:

    • Recommended (default) is the default profile containing a preselected set of IntelliJ inspections

    • Embedded profile lets you select from any available profiles, see the Default profiles section for details

    • Path to the IntelliJ profile lets you specify the path to a custom profile. Make sure that the .idea directory containing the profile file is added to your working directory.

    You can disable certain inspections later using the qodana.yaml file or Profile settings in your HTML report.

    Additional arguments for 'docker run' configures the arguments accepted by a Docker image, see the Docker variables section for details.

    Additional Qodana arguments lets you extend the default Qodana functionality, see the Docker image configuration page for details.

  6. Click Save. Now you can run Qodana in the build.

(Optional) Add a configuration script

Custom profile configuration for Qodana linters is stored in qodana.yaml. When using a CI system, you need to put this file to the working directory manually. Alternatively, you can write a script that will do it for you.

  1. Navigate to your build configuration.

    Navigating to the build configuration

  2. On the build configuration page, select Build Steps from the Edit configuration list.

    Navigating to the step configuration

  3. On the Build steps page, click the Add build step button.

    Creating a new build step

  4. From the Runner type list, select Command Line. On the New Build Step page, you can configure the Command Line runner using the basic options. Otherwise, click Show advanced options to expand the list of configuration options.

    Expanding all configuration options of the Command Line runner

  5. Fill in the fields using the Command Line runner description from the TeamCity documentation portal.

    In the Custom script editor, paste a script that adds a custom qodana.yaml to the working directory. In the example below, the script appends the following inspection exclusions to the configuration file:

    #!/bin/sh FILE="./qodana.yaml" /bin/cat <<EOM >$FILE exclude: - name: Annotator - name: AnotherInspectionId paths: - relative/path - another/relative/path - name: ProhibitedDependencyLicense EOM

Forward reports to Qodana Cloud

To forward reports to Qodana Cloud, follow these steps:

  1. In the TeamCity UI, open the build step that will run Qodana.

  2. In the Cloud Token field, insert the Qodana Cloud token value.

    Configuring fields in TeamCity

Verify inspection results

Now that you have configured and run the build, you can observe inspection results in the TeamCity UI.

  1. Navigate to the project build page. In the Overview tab, click the build entry.

    Navigating to the build entry

  2. On the build page, navigate to the Qodana tab to find the inspection report. To learn more about Qodana reports, see the User interface overview section of this documentation.

    Navigating to the Qodana tab

Last modified: 05 May 2023