Qodana 2022.3 Help

Jenkins

Jenkins is a self-contained, open-source server that automates software-related tasks including building, testing, and deploying software. This section explains how you can configure Docker images of Qodana in Jenkins Multibranch Pipelines, and covers the following cases:

  • Inspecting a specific branch

  • Forwarding inspection results to Qodana Cloud

Prepare your project

Make sure that these plugins are installed on your Jenkins instance:

Make sure that Docker is installed and accessible by Jenkins.

If applicable, make sure that Docker is accessible by the jenkins user as described in the Manage Docker as a non-root user section of the Docker documentation.

Create a Multibranch Pipeline project as described on the Jenkins documentation portal.

In the root directory of your project repository, create the Jenkinsfile. This file will contain Jenkins configuration scripts described in this section.

Basic configuration

This is the basic configuration of the Jenkins Pipeline.

pipeline { agent { docker { args ''' -v "${WORKSPACE}":/data/project --entrypoint="" ''' image 'jetbrains/qodana-<linter>' } } stages { stage('Qodana') { steps { sh ''' qodana \ --fail-threshold <number> ''' } } } }

This configuration uses the docker agent to invoke Qodana Docker images. Using the WORKSPACE variable, the args block mounts the local checkout directory to the project directory of a Docker image, and image specifies the Docker image invoked.

The stage block calls Qodana. Here, you can also specify the options you would like to configure Qodana with.

Inspect specific branches

Using the when block, you can tell Qodana which branches of your project to inspect. For example, this configuration lets you inspect only the feature branch.

pipeline { agent { docker { args ''' -v "${WORKSPACE}":/data/project --entrypoint="" ''' image 'jetbrains/qodana-<linter>' } } stages { stage('Qodana') { when { branch 'feature' } steps { sh '''qodana''' } } } }

You can inspect pull requests as described in the Supporting Pull Requests section of the Jenkins documentation.

Forward reports to Qodana Cloud

The environment block lets you specify the variables and values that are required by Qodana Cloud:

  • QODANA_TOKEN is a Qodana Cloud project token contained as the value for the qodana-token credentials, see the Adding new global credentials section of the Jenkins documentation for details

  • QODANA_REMOTE_URL is the repository URL referring to the GIT_URL environment variable

  • QODANA_BRANCH is the branch name referring to the GIT_BRANCH environment variable

  • QODANA_REVISION is the commit hash referring to the GIT_COMMIT environment variable

  • QODANA_JOB_URL is the job URL referring to the JOB_DISPLAY_URL environment variable

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''' } } } }

Combined configuration

Here is the Jenkins configuration that covers all approaches described in this section.

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') { when { branch 'feature' } steps { sh ''' qodana \ --fail-threshold <number> ''' } } } }
Last modified: 01 February 2023