Build jenkins pipeline for scaner

I’m trying to use sonar scanner 4.3 with jenkins 2.222.3

I have configured the plugin and works fine if I call the scanner from one project, but not from one pipeline.

I’m using this:

node {
  stage('SonarQube analysis') {
    def scannerHome = tool 'SonarQubeScanner';
    withSonarQubeEnv('sonar_scanner') { // If you have configured more than one global server connection, you can specify its name
      sh "${scannerHome}/bin/sonar-scanner"
    }
  }
}

but fails wih

ERROR: No tool named SonarScanner found

I have tried also with
def scannerHome = tool 'SonarQubeScanner 4.0';
as see in the documentation
https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-jenkins/

But the error is the same

ERROR: No tool named SonarScanner 4.0 found

Any idea about how use SonarScanner on a pipeline?

Try adding type: ‘hudson.plugins.sonar.SonarRunnerInstallation’ to your tool definition. So your variable definition looks something like below -

def scannerHome = tool ‘SonarQubeScanner’ type: ‘hudson.plugins.sonar.SonarRunnerInstallation’

1 Like

Thanks!
I just note that Jenkins has a Snippet Generator

The generator give me:

tool name: ‘sonar_scanner’, type: ‘hudson.plugins.sonar.SonarRunnerInstallation’

But still failing

ERROR: SonarQube installation defined in this job (sonar_scanner) does not match any configured installation. Number of installations that can be configured: 1.

My current pipeline:

node {
  stage('SonarQube analysis') {
    def scannerHome = tool name: 'sonar_scanner', type: 'hudson.plugins.sonar.SonarRunnerInstallation';
    withSonarQubeEnv('sonar_scanner') { 
      sh "${scannerHome}/bin/sonar-scanner"
    }
  }
}

Hi

I found the error after read this

I was mixing the names between the tool (sonar_scanner) and the server (SonarQube).

Correct pipeline:

node {
  stage('SonarQube analysis') {
    def scannerHome = tool name: 'sonar_scanner', type: 'hudson.plugins.sonar.SonarRunnerInstallation';
    withSonarQubeEnv('SonarQube') { 
      sh "${scannerHome}/bin/sonar-scanner"
    }
  }
}

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.