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 within Bitbucket Cloud pipelines and covers application of the quality gate and baseline features.

Prepare your project

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

  2. In the Bitbucket Cloud repository, create a pipeline. This will generate the bitbucket-pipelines.yml file for storing a pipeline configuration.

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=$BITBUCKET_CLONE_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. If you are using another Qodana Cloud instance than https://qodana.cloud/, override it by similarly exporting `QODANA_ENDPOINT` as environment variable before running Qodana.

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: 10 July 2024