Jenkins
Edit pageLast modified: 05 March 2025Jenkins 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 Qodana Docker images in Jenkins Multibranch Pipelines.
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
Make sure that these plugins are installed on your Jenkins instance:
Docker and Docker Pipeline are required for running Docker images
git is required for git operations in Jenkins projects
Make sure that Docker is installed and accessible to Jenkins.
If applicable, make sure that Docker is accessible to 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 {
environment {
QODANA_TOKEN=credentials('qodana-token')
}
agent {
docker {
args '''
-v "${WORKSPACE}":/data/project
--entrypoint=""
'''
image 'jetbrains/qodana-<linter>'
}
}
stages {
stage('Qodana') {
steps {
sh '''qodana'''
}
}
}
}
In this configuration, the environment
block defines any environment variables to be used in the pipeline. The QODANA_TOKEN
variable refers to the project token generated in Qodana Cloud and is contained in the qodana-token
global credentials.
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 like the quality gate and baseline features.
Analyze specific branches
Using the when
block, you can tell Qodana which branches of your project to analyze. For example, this configuration lets you analyze only the feature
branch.
pipeline {
environment {
QODANA_TOKEN=credentials('qodana-token')
}
agent {
docker {
args '''
-v "${WORKSPACE}":/data/project
--entrypoint=""
'''
image 'jetbrains/qodana-<linter>'
}
}
stages {
stage('Qodana') {
when {
branch 'feature'
}
steps {
sh '''qodana'''
}
}
}
}
You can analyze pull requests as described in the Supporting Pull Requests section of the Jenkins documentation.
Quality gate and baseline
This configuration invokes the quality gate and baseline features using the --fail-threshold <number>
and --baseline <path/to/qodana.sarif.json>
lines specified in the steps
block.
pipeline {
environment {
QODANA_TOKEN=credentials('qodana-token')
}
agent {
docker {
args '''
-v "${WORKSPACE}":/data/project
--entrypoint=""
'''
image 'jetbrains/qodana-<linter>'
}
}
stages {
stage('Qodana') {
steps {
sh '''
qodana \
--fail-threshold <number> \
--baseline <path/to/qodana.sarif.json>
'''
}
}
}
}