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
Using the Bitbucket Cloud UI, create a repository.
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.
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=$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-<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=$BITBUCKET_CLONE_DIR/.qodana/cache
artifacts:
- .qodana/report
definitions:
caches:
qodana: .qodana/cache
Last modified: 12 April 2024