Qodana 2023.2 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> 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.

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-&lt;linter&gt; 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=$BITBUCKET_CLONE_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-&lt;linter&gt; 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=$BITBUCKET_CLONE_DIR/.qodana/cache artifacts: - .qodana/report definitions: caches: qodana: .qodana/cache
Last modified: 15 September 2023