Qodana 2022.3 Help

Forward reports

To forward reports to Qodana Cloud, you need to provide data contained as values for these variables:

Variable name

Description

QODANA_TOKEN

Unique project token of Qodana Cloud

QODANA_REMOTE_URL

Project URL

QODANA_BRANCH

Name of the branch inspected

QODANA_REVISION

Commit hash

QODANA_JOB_URL

Job URL

This section explains how you can generate values for these variables and forward Qodana reports to Qodana Cloud using this software:

For all these cases, you need to generate a unique Qodana Cloud project token as shown in the Manage a project section of this documentation.

Docker

This is the basic Docker CLI command that sets all variables required by Qodana Cloud:

docker run \ -v $(pwd)/project/:/data/project/ \ -e QODANA_TOKEN="<qodana-cloud-token>" \ -e QODANA_REMOTE_URL="<project-remote-url>" \ -e QODANA_BRANCH="<project-branch-name>" \ -e QODANA_REVISION="<commit-hash>" \ -e QODANA_JOB_URL="<job-url>" \ jetbrains/qodana-<linter>

The QODANA_TOKEN variable of this command requires the project token generated in Qodana Cloud.

This command implies that values for all variables should be provided manually, which is not convenient. Fortunately, you can overcome it using various CI/CD solutions that provide all data required by Qodana Cloud, or contain predefined environment variables that refer to the data required by Qodana Cloud.

Azure Pipelines

  1. In the Azure Pipelines UI, create the QODANA_TOKEN secret variable and save the project token as its value.

  2. In the Azure pipeline file, add QODANA_TOKEN variable to the env section of the QodanaScan task:

- task: QodanaScan@2022 env: QODANA_TOKEN: $(QODANA_TOKEN)

The rest variables and values required by Qodana Cloud are automatically generated by QodanaScan.

To learn more about Qodana integration with Azure Pipelines, see the Azure Pipelines section of this documentation.

CircleCI

To forward inspection results to Qodana Cloud, all you need to do is to create the QODANA_TOKEN project variable and save the project token as its value.

After the token is set for analysis, all Qodana job results will be uploaded to your Qodana Cloud project.

To learn more about Qodana integration with CircleCI, see the CircleCI section of this documentation.

GitHub Actions

1. In the GitHub UI, create the QODANA_TOKEN encrypted secret and save the project token as its value.

2. In a GitHub workflow, add this snippet to invoke the Qodana Scan action:

- name: 'Qodana Scan' uses: JetBrains/qodana-action@main env: QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

The rest variables and values required by Qodana Cloud are automatically generated by Qodana Scan.

To learn more about Qodana integration with GitHub, see the GitHub Actions section of this documentation.

GitLab CI/CD

1. In the root folder of your GitLab-hosted project, create the .gitlab-ci.yml file and save this configuration to that file:

qodana: image: name: jetbrains/qodana-<linter> entrypoint: [""] variables: QODANA_TOKEN: <your-project-token> QODANA_REMOTE_URL: git@$CI_SERVER_HOST:$CI_PROJECT_PATH.git QODANA_BRANCH: $CI_COMMIT_BRANCH QODANA_REVISION: $CI_COMMIT_SHA QODANA_JOB_URL: $CI_JOB_URL script: - qodana artifacts: paths: - qodana

2. In this configuration, provide the project token as the value for the QODANA_TOKEN variable.

3. In the image:name section of this configuration, specify the name of the Qodana Docker image.

To learn more about Qodana integration with GitLab CI/CD, see the GitLab CI/CD section of this documentation.

Jenkins

1. In the Jenkins UI, create the credentials with the qodana-token name as described in the Adding new global credentials section of the Jenkins documentation, and save the project token as the value for these credentials.

2. In the root directory of your project, create the Jenkinsfile file and save this configuration to that file:

pipeline { environment { QODANA_TOKEN=credentials('qodana-token') QODANA_REMOTE_URL="${GIT_URL}" QODANA_BRANCH="${GIT_BRANCH}" QODANA_REVISION="${GIT_COMMIT}" QODANA_JOB_URL="${JOB_DISPLAY_URL}" } agent { docker { args ''' -v "${WORKSPACE}":/data/project --entrypoint="" ''' image 'jetbrains/qodana-<linter>' } } stages { stage('Qodana') { steps { sh '''qodana''' } } } }

3. In the image section of this script, specify the Qodana Docker image name.

To learn more about Qodana integration with Jenkins, see the Jenkins section of this documentation.

Space Automation

1. In the JetBrains Space UI, create a secret with the qodana-token name, and save the generated project token as its value.

2. In the root directory of your Space-based project, create the .space.kts file and save this configuration script to that file:

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() } } }

3. In the container section of this script, specify the Qodana Docker image name.

To learn more details about Qodana integration with Space Automation, see the Space Automation section of this documentation.

TeamCity

1. In the TeamCity UI, create the QODANA_TOKEN environment variable of the password type, and save the project token as its value.

2. Open the build step that will run Qodana.

3. In the Additional arguments for 'docker run' field, add this line to employ the QODANA_TOKEN variable:

-e QODANA_TOKEN=%env.QODANA_TOKEN%
Configuring fields in TeamCity

The rest variables and values required by Qodana Cloud are automatically generated by TeamCity.

To learn more about Qodana integration with TeamCity, see the TeamCity section of this documentation.

Last modified: 27 January 2023