Uploaded image for project: 'SonarQube'
  1. SonarQube
  2. SONAR-13296

Explain how to set up Jenkins for analysis with SonarQube and Bitbucket Server

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 8.4
    • Component/s: Web
    • Labels:
      None
    • Estimate:
      Days
    • Edition:
      Developer
    • Production Notes:
      None

      Description

      What

      We will create a new tutorial for people using Bitbucket Server and Jenkins. Once a user has imported a repository from Bitbucket Server (see MMF-1863), we display 2 options:

      • Set up analysis manually
      • Set up analysis using Jenkins CI

      If the user clicks on manually, we show the existing tutorial. If the user clicks on Jenkins CI, we show a new tutorial. See the mockups.

      Important notes

      Because we know what Bitbucket Server instance we're talking about, we should replace the BITBUCKET_URL token from the Webhook creation step automatically. Furthermore, we can link directly to the correct page on Bitbucket Server for the Webhook creation, which is /plugins/servlet/webhooks/projects/BBS_PROJECT_KEY/repos/BBS_REPO_SLUG/create.

      Snippets

      In all snippets, we obviously replace the PROJECT_KEY token with the actual key of the current project.

      Maven

      Add to pom.xml:

        <properties>
          <sonar.projectKey>PROJECT_KEY</sonar.projectKey>
        </properties>
      

      Create Jenkinsfile:

      node {
        stage('SCM') {
          checkout scm
        }
        stage('SonarQube Analysis') {
          def mvn = tool 'Default Maven'; // Replace with Global Tool > Maven > Maven installations > Name
          withSonarQubeEnv() {
            sh "${mvn}/bin/mvn sonar:sonar"
          }
        }
      }
      

      Gradle

      Add to build.gradle:

      plugins {
        id "org.sonarqube" version "2.7"
      }
      
      sonarqube {
        properties {
          property "sonar.projectKey", "PROJECT_KEY"
        }
      }
      

      Create Jenkinsfile:

      node {
        stage('SCM') {
          checkout scm
        }
        stage('SonarQube Analysis') {
          withSonarQubeEnv() {
            sh "./gradlew sonarqube"
          }
        }
      }
      

      MS Build

      Create Jenkinsfile:

      node {
        stage('SCM') {
          checkout scm
        }
        stage('SonarQube Analysis') {
          def msbuildHome = tool 'Default MSBuild' // Replace with Global Tool > MSBuild > MSBuild installations > Name
          def scannerHome = tool 'SonarScanner for MSBuild' // Replace with Global Tool > SonarScanner for MSBuild > SonarScanner for MSBuild installations > Name
          withSonarQubeEnv() {
            bat "\"${scannerHome}\\SonarScanner.MSBuild.exe\" begin /k:\"PROJECT_KEY\""
            bat "\"${msbuildHome}\\MSBuild.exe\" /t:Rebuild"
            bat "\"${scannerHome}\\SonarScanner.MSBuild.exe\" end"
          }
        }
      }
      

      Other

      Create sonar-project.properties file:

      sonar.projectKey=PROJECT_KEY
      

      Create Jenkinsfile:

      node {
        stage('SCM') {
          checkout scm
        }
        stage('SonarQube Analysis') {
          def scannerHome = tool 'SonarScanner'; // Replace with Global Tool > SonarQube Scanner > SonarQube Scanner installations > Name
          withSonarQubeEnv() {
            sh "${scannerHome}/bin/sonar-scanner"
          }
        }
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              wouter.admiraal Wouter Admiraal
              Reporter:
              wouter.admiraal Wouter Admiraal
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: