Qodana 2024.3 Help

TeamCity

Qodana is available in TeamCity as the Qodana build runner. 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 to the users TeamCity is running under. TeamCity agents hosted by JetBrains already meet this condition.

Add the Qodana runner

  1. In the TeamCity UI, navigate to the configuration page of a build where you would like to run Qodana.

  2. On the Build Configuration Settings page, navigate to the Build steps page.

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

  4. On the page that opens, select the Qodana runner.

  5. On the New Build Step: Qodana page, click Show advanced options and configure the Qodana runner:

    • Step name uniquely identifies this step among other build steps.

    • Step ID 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, see the TeamCity documentation for details. 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 the TeamCity UI. Using this option, you can view codebase problems along with other problems detected.

    • Linter configures the Qodana linter.

      Here, specify the linter that you would like to run.

    • Version is by default set to Latest.

    • Inspection profile defines an inspection profile:

      • Recommended (default) is one of the default profiles.

      • Embedded profile lets you select a default profile, see the Existing Qodana profiles section for details.

      • Path to the IntelliJ profile lets you specify the path to your custom profile. To use this option, make sure that you also configure the custom profile in the qodana.yaml file.

    • Cloud Token configures a project token generated in Qodana Cloud.

    • Additional Docker arguments configures the arguments accepted by a Docker image, see the Shell commands section for details.

    • Additional Qodana arguments lets you extend the default Qodana functionality, see the Options section for details.

    Configuring the Qodana runner
  6. Click the Save button.

Quality gate and baseline

Using the Additional Qodana arguments field of the Qodana runner configuration, you can configure the quality gate and baseline features:

  • --fail-threshold <number> option for configuring a quality gate,

  • --baseline <path/to/qodana.sarif.json> option for configuring a baseline.

To configure both options, in the Additional Qodana arguments field separate them using a space character:

--fail-threshold <number> --baseline <path/to/qodana.sarif.json>

Analyze pull requests and specific branches

Information about configuring TeamCity for analyzing pull and merge requests is available on the TeamCity documentation portal.

To learn how to analyze specific branches, see the Trigger Settings section of the TeamCity documentation.

Add a configuration script

Custom profile configuration for Qodana linters is stored in the qodana.yaml file. 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. In the TeamCity UI, navigate to the configuration page of a build where you would like to run Qodana.

  2. On the Build Configuration Settings page, navigate to the Build steps page.

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

  4. On the page that opens, select the Command line runner.

  5. Configure the Command line runner as described on the TeamCity documentation portal.

    Expanding all configuration options of the Command Line runner
  6. In the Custom script field, paste a script that adds a custom qodana.yaml file 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

Verify inspection results

Now that you have configured and run the build, you can examine analysis results in Qodana Cloud.

Alternatively, you can view analysis results using the TeamCity UI, follow the steps below:

  1. Navigate to a project build page. On 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 Inspection report section of this documentation.

    Navigating to the Qodana tab
Last modified: 20 September 2024