Qodana 2024.1 ヘルプ

Bitbucket クラウド

Bitbucket クラウド(英語)は、チームがコードを計画、共同作業、テスト、デプロイするための 1 つの場所を提供するツールです。このセクションでは、Bitbucket クラウドパイプライン(英語)内で Qodana Docker イメージを実行する方法について説明し、品質ゲートベースライン機能の適用について説明します。

プロジェクトを準備する

  1. Bitbucket クラウド UI を使用して、リポジトリ(英語)を作成します。

  2. Bitbucket クラウドリポジトリで、パイプライン(英語)を作成します。これにより、パイプライン構成を保存するための bitbucket-pipelines.yml ファイルが生成されます。

基本構成

以下は、Bitbucket クラウドパイプラインで Qodana を実行できるようにする bitbucket-pipelines.yml ファイルの基本構成スニペットです。

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

ここで、branches ブロックはどのブランチをインスペクションするかを指定します。

image ブロックは、パイプラインで呼び出される Qodana リンターを指定します。

script ブロックには、Qodana Cloud に必要なプロジェクトトークンを指定し、$QODANA_TOKEN 変数(英語)として保存される - export QODANA_TOKEN=$QODANA_TOKEN 行が含まれています。このブロックの - qodana ... 行は、パイプラインの実行中に使用するディレクトリを Bitbucket に指示し、Qodana オプションを含めることもできます。

この構成は、このセクションのすべての例の基礎として使用されます。

クオリティゲート

--fail-threshold オプションを使用すると、プロジェクトで受け入れられる問題の制限を構成できます。

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 <path/to/qodana.sarif.json> オプションを使用して、ベースラインとして使用される SARIF 形式のファイルへのパスを指定します。

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

コードインサイトレポートを生成する

Qodana のバージョン 2024.1 以降では、Bitbucket Cloud のプルリクエスト UI を使用して、問題のある特定のコード行とその説明、改善の推奨事項を表示できます。デフォルトでは、Qodana はコードインサイト(英語)レポートを生成し、Bitbucket Code Insights API を使用して転送します。構成は必要ありません。