Execute SonarQube Scanner within Jenkins 2 Pipeline

Christoph Forster picture Christoph Forster · Jun 30, 2016 · Viewed 17.6k times · Source

I want to execute a "SonarQube Scanner" Step within my Jenkins 2.x Pipeline.

When I try to create a sample groovy within the pipeline-syntax I only get a groovy script of the following format:

step <object of type hudson.plugins.sonar.SonarRunnerBuilder>

Does anyone know what is the correct Step Syntax? E.g. Publish JUnit Report looks like

step([$class: 'JUnitResultArchiver', testResults: ''])

I use the following Versions:

  • Jenkins 2.11
  • SonarQube Scanner 2.6.1
  • SonarQube Plugin 2.4.1

Answer

Christoph Forster picture Christoph Forster · Jun 30, 2016

I think I got it. First you have to retrieve your SonarQube Scanner Tool

def sonarqubeScannerHome = tool name: 'SonarQubeScanner', type: 'hudson.plugins.sonar.SonarRunnerInstallation'

Then you can call sonar-scanner via Shell:

sh "${sonarqubeScannerHome}/bin/sonar-scanner -e -Dsonar.host.url=..."