Qodana 2024.3 Help

Bitbucket Cloud

Bitbucket Cloud is a tool that gives teams one place to plan, collaborate, test, and deploy their code. This section explains how you can run Qodana Docker images in Bitbucket Cloud pipelines and covers application of the quality gate and baseline features.

Before you start

Qodana Cloud

All configuration examples in this section use a project token generated by Qodana Cloud. This token is required for the paid Qodana linters and optional for use with the Community linters. You can see these sections to learn how to generate the project token in the Qodana Cloud UI:

  • The project setup section explains how to generate a project token when first working with Qodana Cloud.

  • The Manage a project section explains how to create a project token within an existing Qodana Cloud organization.

Once you obtain the project token, you can use the QODANA_TOKEN variable for identifying in a pipeline or workflow.

If you are using a Qodana Cloud instance other than https://qodana.cloud/, override it by setting the QODANA_ENDPOINT environment variable.

Prepare your project

  1. Using the Bitbucket Cloud UI, create a repository.

  2. In the Bitbucket Cloud repository, create a pipeline.

Basic configuration

Here is the basic configuration snippet for the bitbucket-pipelines.yml file that lets you run Qodana in Bitbucket Cloud pipelines:

image: atlassian/default-image:4 pipelines: branches: main: - step: name: Qodana caches: - qodana image: jetbrains/qodana-<linter> # Specify a Qodana linter here. For example, jetbrains/qodana-jvm:latest script: - export QODANA_TOKEN=$QODANA_TOKEN # Export the environment variable - qodana --results-dir=$BITBUCKET_CLONE_DIR/.qodana --report-dir=$BITBUCKET_CLONE_DIR/.qodana/report --cache-dir=~/.qodana/cache artifacts: - .qodana/report definitions: caches: qodana: .qodana/cache

Here, the branches block specifies which branches to inspect.

The image block specifies the Qodana linter that will be invoked in the pipeline.

The script block contains the - export QODANA_TOKEN=$QODANA_TOKEN line that specifies the project token required by Qodana Cloud and saved as the $QODANA_TOKEN variable. The - qodana ... line in this block tells Bitbucket which directories to use while running the pipeline, and it can also contain Qodana options.

This configuration will be used as a basis for all examples in this section.

Quality gate

Using the --fail-threshold option, you can configure the limit of problems accepted in your project:

image: atlassian/default-image:4 pipelines: branches: main: - step: name: Qodana caches: - qodana image: jetbrains/qodana-<linter> # Specify a Qodana linter here. For example, jetbrains/qodana-jvm:latest script: - export QODANA_TOKEN=$QODANA_TOKEN # Export the environment variable - qodana --fail-threshold <number-of-problems> --results-dir=$BITBUCKET_CLONE_DIR/.qodana --report-dir=$BITBUCKET_CLONE_DIR/.qodana/report --cache-dir=~/.qodana/cache artifacts: - .qodana/report definitions: caches: qodana: .qodana/cache

Baseline

Use the --baseline <path/to/qodana.sarif.json> option to specify the path to the SARIF-formatted file used as a baseline:

image: atlassian/default-image:4 pipelines: branches: main: - step: name: Qodana caches: - qodana image: jetbrains/qodana-<linter> # Specify a Qodana linter here. For example, jetbrains/qodana-jvm:latest script: - export QODANA_TOKEN=$QODANA_TOKEN # Export the environment variable - qodana --baseline <path/to/qodana.sarif.json> --results-dir=$BITBUCKET_CLONE_DIR/.qodana --report-dir=$BITBUCKET_CLONE_DIR/.qodana/report --cache-dir=~/.qodana/cache artifacts: - .qodana/report definitions: caches: qodana: ~/.qodana/cache

Generate Code Insights reports

Starting from version 2024.1 of Qodana, using the pull request UI of Bitbucket Cloud, you can view specific lines of code that contain problems along with their description and recommendations for improvement. By default, Qodana generates Code Insights reports, forwards them using the Bitbucket Code Insights API, and does not require any configuration.

Last modified: 05 March 2025