On this page

analysis-prerequisitesInstalling and Configuring your Jenkins pluginsConfiguring single branch pipeline jobsConfiguring multi-branch pipeline jobs

Jenkins integration

SonarScanners running in Jenkins can automatically detect branches and pull requests in certain jobs. You don't need to explicitly pass the branch or pull request details.

analysis-prerequisites

To run project analysis with Jenkins, you need to install and configure the following Jenkins plugins in Jenkins:

See the Installing and Configuring your Jenkins plugins section below for more information.

Installing and Configuring your Jenkins plugins

SonarQube Scanner plugin

Click SonarQube Scanner below to expand instructions on installing and configuring the plugin.

Branch Source plugin

Required to analyze multibranch pipeline jobs in Developer Edition or above

Click your DevOps Platform below to expand the instructions on installing and configuring the Branch Source plugin.

Configuring Jenkins through the SonarQube tutorial

You can easily configure and analyze your projects with Jenkins through the tutorial in SonarQube.

To access the tutorial:

  1. Click the Add project drop-down in the upper-right corner of the Projects page in SonarQube and select your DevOps platform.
  2. Select the repository you want to import into SonarQube.
  3. When asked How do you want to analyze your repository?, select With Jenkins.

See the Installing and Configuring your Jenkins plugins section below to set up your Jenkins plugins before going through the tutorial.

Configuring single branch pipeline jobs

With Community Edition, you can only analyze a single branch. For more information, see the Jenkins extension for SonarQube documentation.

Configuring multi-branch pipeline jobs

Starting in Developer Edition, you can analyze multiple branches and Pull Requests. The automatic configuration of branches and Pull Requests relies on environment variables available in Multibranch Pipeline jobs. These are set based on information exported by Jenkins plugins.

For configuration examples, see the Jenkins extension for SonarQube documentation.

Configuring Multibranch Pipeline jobs for Pull Request Decoration

You need to configure your Multibranch Pipeline job correctly to avoid issues with Pull Request decoration. From your Multibranch Pipeline job in Jenkins, go to Configure > Branch Sources > Behaviors.

For Bitbucket and GitHub, under Discover pull requests from origin, make sure The current pull request revision is selected.

For GitLab, under Discover merge requests from origin, make sure The current merge request revision is selected.

© 2008-2022, SonarSource S.A, Switzerland. Except where otherwise noted, content in this space is licensed under a Creative Commons Attribution-NonCommercial 3.0 United States License. SONARQUBE is a trademark of SonarSource SA. All other trademarks and copyrights are the property of their respective owners.

Creative Commons License