Qodana 2024.3 Help

Space Automation

Space Automation is a CI/CD tool that helps you automate development workflows in the JetBrains Space environment. This section explains how you can configure and run Qodana Docker images within Space Automation jobs.

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

Assuming that your JetBrains Space account already has a project and a repository, in the project root create the .space.kts file. This file will contain configuration scripts written in Kotlin and mentioned in this section.

Basic configuration

This is the basic configuration script for running Qodana in JetBrains Automation jobs.

job("Qodana") { container("jetbrains/qodana-<linter>") { env["QODANA_TOKEN"] = Secrets("qodana-token") shellScript { content = """ qodana """.trimIndent() } } }

The container block specifies which Docker image of Qodana to run.

The QODANA_TOKEN variable refers to the project token generated in Qodana Cloud and contained in the qodana-token secret. Once the project token is generated, in the Settings section of your JetBrains Space environment create a secret with the qodana-token name. Save the project token as the value for this secret.

The shellScript block contains the qodana command for running Qodana, and it can also contain the options that can be used during the run like quality gate or baseline.

Analyze specific branches

The startOn block lets you specify the event that will trigger a job. This configuration uses the nested branchFilter block to override the default trigger and run the job only after changes made in the feature branch.

The codeReviewOpened trigger lets you analyze code reviews opened in the default branch of the project.

job("Qodana") { startOn { gitPush { branchFilter { +"refs/heads/feature" } } codeReviewOpened{} } container("jetbrains/qodana-<linter>") { env["QODANA_TOKEN"] = Secrets("qodana-token") shellScript { content = """ qodana """.trimIndent() } } }

Quality gate and baseline

You can use the --fail-threshold <number> and --baseline <path/to/qodana.sarif.json> lines in the shellScript block to invoke the quality gate and baseline features.

job("Qodana") { container("jetbrains/qodana-<linter>") { env["QODANA_TOKEN"] = Secrets("qodana-token") shellScript { content = """ qodana \ --fail-threshold <number> \ --baseline <path/to/qodana.sarif.json> """.trimIndent() } } }
Last modified: 05 March 2025