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

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.

job("Qodana") { container("jetbrains/qodana-<linter>") { shellScript { content = """ qodana --fail-threshold <number> --profile-name <profile-name> """.trimIndent() } } }

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

The shellScript block contains the qodana command for running Qodana and enumerates the options that should be used during the run.

Inspect 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 inspect code reviews opened in the default branch of the project.

job("Qodana") { startOn { gitPush { branchFilter { +"refs/heads/feature" } } codeReviewOpened{} } container("jetbrains/qodana-<linter>") { shellScript { content = """qodana""" } } }

Forward report to Qodana Cloud

Once you generated a project token in Qodana Cloud, 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.

Below is the script that lets you forward inspection reports to Qodana Cloud. It defines the QODANA_TOKEN variable that refers to the qodana-token secret.

The QODANA_REMOTE_URL, QODANA_BRANCH, and QODANA_REVISIONvariables provide information about the repository URL, name of the inspected branch, and commit hash.

job("Qodana") { container("jetbrains/qodana-<linter>") { env["QODANA_TOKEN"] = Secrets("qodana-token") shellScript { content = """ QODANA_REMOTE_URL="ssh://git@git.${'$'}JB_SPACE_API_URL/${'$'}JB_SPACE_PROJECT_KEY/${'$'}JB_SPACE_GIT_REPOSITORY_NAME.git" \ QODANA_BRANCH=${'$'}JB_SPACE_GIT_BRANCH \ QODANA_REVISION=${'$'}JB_SPACE_GIT_REVISION \ qodana """.trimIndent() } } }

Combined configuration

This configuration script combines all approaches from this section.

job("Qodana") { startOn { gitPush { branchFilter { +"refs/heads/feature" } } codeReviewOpened{} } container("jetbrains/qodana-<linter>") { env["QODANA_TOKEN"] = Secrets("qodana-token") shellScript { content = """ QODANA_REMOTE_URL="ssh://git@git.${'$'}JB_SPACE_API_URL/${'$'}JB_SPACE_PROJECT_KEY/${'$'}JB_SPACE_GIT_REPOSITORY_NAME.git" \ QODANA_BRANCH=${'$'}JB_SPACE_GIT_BRANCH \ QODANA_REVISION=${'$'}JB_SPACE_GIT_REVISION \ qodana --fail-threshold <number> --profile-name <profile-name> """.trimIndent() } } }
Last modified: 18 January 2023