Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

HTML
<div class="table-wrap"><table style="line-height: 1.4285715;" class="confluenceTable"><tbody><tr><td class="highlight-grey confluenceTd" data-highlight-colour="grey">By <a target="_top" href="https://www.sonarsource.com">SonarSource</a> &#8211; GNU LGPL 3 &#8211;
<a target="_top" href="https://jira.sonarsource.com/browse/SONARJNKNS">Issue Tracker</a> &#8211;
<a target="_top" href="https://github.com/SonarSource/sonar-scanner-jenkins">Sources</a>
<br>
<div>
    <div style="padding-top:10px;padding-bottom:5px">
    <span style="font-size:larger;"><strong>SonarQube Scanner for Jenkins 2.8.1<9</strong></span>
    <br>
    </div> 
</div> 
</div> </td></tr></tbody></table></div>

...

  • SonarQube Scanner
  • SonarQube Scanner for Maven
  • SonarQube Scanner for MaveGradle
  • SonarScanner for MSBuild

Once the job is complete, the plugin will detect that a SonarQube analysis was made during the build and display a badge and a widget on the job page with a link to the SonarQube dashboard as well as quality gate status.

Status
colourGreen
titleSince 2.5
 : you can also use Jenkins Pipeline DSL (some features require SonarQube >= 6.2).

Compatibility

SonarQube Scanner for Jenkins

2.02.12.2.x2.3 - 2.4.x2.52.62.7 - 2.
8.1
9

Jenkins

1.344+1.491+1.580.1+1.580.3+2.7.3+
2.32.2+2.89.4+

Status
colourGreen
titleSince 2.5
 Analysis must run with a JRE8

...

  1. Configure the project, and scroll down to the Build section.
  2. Add both the SonarQube for MSBuild - Begin Analysis and SonarQube for MSBuild - End Analysis build steps to your build
  3.  Configure the SonarQube Project KeyName and Version in the SonarQube Scanner for MSBuild - Begin Analysis build step
  4. Use the MSBuild build step or the Execute Windows batch command to execute the build with MSBuild 14 (see compatibility) between the Begin Analysis and End Analysis steps.

 


Analyzing with SonarQube Scanner for Maven or Gradle

...

  1. Configure the project, and scroll down to the Build Environment section.
  2. Enable Prepare SonarQube Scanner environment to allow the injection of SonarQube server values into this particular job. If multiple SonarQube instances are configured, you will be able to choose which one to use.

    Tip

    Press the help button to learn which variables you can use in your build. Some values may be blank, depending on what was defined for the server.

     

     

     





  3. Once the environment variables are available, use them in a standard Maven build step (Invoke top-level Maven targets) by setting the Goals to include, or a standard Gradle build step (Invoke Gradle script) by setting the Tasks to execute:

    Code Block
    languagebash
    titleMaven goal
    $SONAR_MAVEN_GOAL -Dsonar.host.url=$SONAR_HOST_URL


    Code Block
    languagebash
    titleGradle task
    sonarqube -Dsonar.host.url=$SONAR_HOST_URL

    In both cases, launching your analysis may require authentication. In that case, make sure that the Global Configuration defines a valid SonarQube token, and add it to the Maven goal or Gradle task with the following argument and value: -Dsonar.login=$SONAR_AUTH_TOKEN

 


Note
The Post-build Action for Maven analysis is still available, but is deprecated.

...

Code Block
languagegroovy
titleSonarQube Scanner for MSBuild
node {
  stage('SCM') {
    git 'https://github.com/foo/bar.git'
  }
  stage('Build + SonarQube analysis') {
    def sqScannerMsBuildHome = tool 'Scanner for MSBuild 2.2'
    withSonarQubeEnv('My SonarQube Server') {
      // Due to SONARMSBRU-307 value of sonar.host.url and credentials should be passed on command line
      bat "${sqScannerMsBuildHome}\\SonarQube.Scanner.MSBuild.exe begin /k:myKey /n:myName /v:1.0 /d:sonar.host.url=%SONAR_HOST_URL% /d:sonar.login=%SONAR_AUTH_TOKEN%"
      bat 'MSBuild.exe /t:Rebuild'
      bat "${sqScannerMsBuildHome}\\SonarQube.Scanner.MSBuild.exe end /d:sonar.login=%SONAR_AUTH_TOKEN%"
    }
  }
}

Pause pipeline until quality gate is computed

...

Code Block
languagegroovy
titleMultiple analyses
pipeline {
    agent any
    stages {
        stage('SonarQube analysis 1') {
            steps {
                sh 'mvn clean package sonar:sonar'
            }
        }
        stage("Quality Gate 1") {
            steps {
                waitForQualityGate abortPipeline: true
            }
        }
        stage('SonarQube analysis 2') {
            steps {
                sh 'gradle sonarqube'
            }
        }
        stage("Quality Gate 2") {
            steps {
                waitForQualityGate abortPipeline: true
            }
        }
    }
}