From bd3b1d2b2e5c0dd23f3d52f11d506d8c04c74ca1 Mon Sep 17 00:00:00 2001 From: michaelbirnstiehl Date: Thu, 28 Jan 2021 14:23:04 -0600 Subject: [PATCH] SONAR-14362 describe how to analyze only the main branch in Jenkins --- .../sonar-docs/src/pages/analysis/jenkins.md | 71 ++++++++++--------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/server/sonar-docs/src/pages/analysis/jenkins.md b/server/sonar-docs/src/pages/analysis/jenkins.md index 7fd78f40f89..092eb5609b6 100644 --- a/server/sonar-docs/src/pages/analysis/jenkins.md +++ b/server/sonar-docs/src/pages/analysis/jenkins.md @@ -3,21 +3,52 @@ title: Jenkins url: /analysis/jenkins/ --- -_Pull Request analysis is available starting in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html)._ - SonarScanners running in Jenkins can automatically detect branches and Merge or Pull Requests in certain jobs. You don't need to explicitly pass the branch or Pull Request details. ## Analysis Prerequisites -For analysis with Jenkins, you need to have the following Jenkins plugins installed and configured _in Jenkins_: -- The Branch Source plugin that corresponds to your ALM (Bitbucket, GitHub, or GitLab). +To run project analysis with Jenkins, you need to install and configure the following Jenkins plugins _in Jenkins_: + - The SonarQube Scanner plugin. +- The Branch Source plugin that corresponds to your ALM (Bitbucket Server or GitHub) if you're analyzing multibranch pipeline jobs in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html) or above. + +See the **Installing and Configuring your Jenkins plugins** section below for more information. + +### Configuring Jenkins using the SonarQube tutorial -### Bitbucket Server and GitHub Tutorial +If you're using Bitbucket Server, GitHub Enterprise, or GitHub.com, you can easily configure and analyze your projects by following the tutorial in SonarQube. You can access the tutorial by going to your project's **Overview** page and selecting **with Jenkins** under "How do you want to analyze your repository?" -With Bitbucket Server and GitHub, you can easily configure and analyze your projects by following the tutorial in SonarQube (which you can find by selecting **with Jenkins** when asked how you want to analyze your repository). Before going through the tutorial, you need to set up your Branch Source plugin and SonarQube Scanner plugin. Below you'll find recommended configurations. +[[info]] +|See the **Installing and Configuring your Jenkins plugins** section below to set up your Jenkins plugins before going through the tutorial. -#### **Branch Source plugin** +## Installing and Configuring your Jenkins plugins + +### SonarQube Scanner plugin + +Click SonarQube Scanner below to expand instructions on installing and configuring the plugin. + +[[collapse]] +| ## SonarQube Scanner +| +| [SonarQube Scanner plugin](https://plugins.jenkins.io/sonar/) version 2.11 or later is required. +| +| 1. From the Jenkins Dashboard, navigate to **Manage Jenkins > Manage Plugins** and install the **SonarQube Scanner** plugin. +| 1. Back at the Jenkins Dashboard, navigate to **Credentials > System** from the left navigation. +| 1. Click the **Global credentials (unrestricted)** link in the **System** table. +| 1. Click **Add credentials** in the left navigation and add the following information: +| - **Kind**: Secret Text +| - **Scope**: Global +| - **Secret**: Generate a token at **User > My Account > Security** in SonarQube, and copy and paste it here. +| 1. Click **OK**. +| 1. From the Jenkins Dashboard, navigate to **Manage Jenkins > Configure System**. +| 1. From the **SonarQube Servers** section, click **Add SonarQube**. Add the following information: +| - **Name**: Give a unique name to your SonarQube instance. +| - **Server URL**: Your SonarQube instance URL. +| - **Credentials**: Select the credentials created during step 4. +| 1. Click **Save** + +### Branch Source plugin +_Required to analyze multibranch pipeline jobs in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html) or above_ Click your ALM below to expand the instructions on installing and configuring the Branch Source plugin. @@ -46,30 +77,6 @@ Click your ALM below to expand the instructions on installing and configuring th | 1. From the **GitHub** or **GitHub Enterprise Servers** section, add your GitHub server. | 1. Click **Save**. -#### **SonarQube Scanner plugin** - -Click SonarQube Scanner below to expand instructions on installing and configuring the plugin. - -[[collapse]] -| ## SonarQube Scanner -| -| [SonarQube Scanner plugin](https://plugins.jenkins.io/sonar/) version 2.11 or later is required. -| -| 1. From the Jenkins Dashboard, navigate to **Manage Jenkins > Manage Plugins** and install the **SonarQube Scanner** plugin. -| 1. Back at the Jenkins Dashboard, navigate to **Credentials > System** from the left navigation. -| 1. Click the **Global credentials (unrestricted)** link in the **System** table. -| 1. Click **Add credentials** in the left navigation and add the following information: -| - **Kind**: Secret Text -| - **Scope**: Global -| - **Secret**: Generate a token at **User > My Account > Security** in SonarQube, and copy and paste it here. -| 1. Click **OK**. -| 1. From the Jenkins Dashboard, navigate to **Manage Jenkins > Configure System**. -| 1. From the **SonarQube Servers** section, click **Add SonarQube**. Add the following information: -| - **Name**: Give a unique name to your SonarQube instance. -| - **Server URL**: Your SonarQube instance URL. -| - **Credentials**: Select the credentials created during step 4. -| 1. Click **Save** - ## Configuring Single Branch Pipeline jobs With Community Edition, you can only analyze a single branch. For more information, see the [SonarScanner for Jenkins](/analysis/scan/sonarscanner-for-jenkins/) documentation. @@ -79,7 +86,7 @@ Starting in [Developer Edition](https://redirect.sonarsource.com/editions/develo For configuration examples, see the [SonarScanner for Jenkins](/analysis/scan/sonarscanner-for-jenkins/) documentation. -### Setting your Branch Source Plugin for Pull Request Decoration +### 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 > Discover pull requests from origin** and make sure **The current pull request revision** is selected. ## Detecting changed code in Pull Requests -- 2.39.5