Add SonarQube to jenkins job pipeline failed

2019-09-14 20:30发布

问题:

At the moment we try to add SonarQube analyzing to our jenkins job pipeline. But every time the build job failed with the message: "java.lang.NoSuchMethodError: **No such DSL method withSonarQubeEnv". We have reinstall all plugins and configurations. Nothing help. So maybe someone of you can help us.

What we have done:

Do all steps of this tutorial from sonarqube: Analyzing with SonarQube Scanner for Jenkins

  • Install SonarQube Plugin 2.5
  • Add and configure SonarQube under Manage Jenkins > Configure System
  • Add SonarQube Scanner under Manage Jenkins > Global Tool Configuration
  • Add this code after the checkout of our project to the groovy file for the pipeline:

    stage('SonarQube analysis')
    // requires SonarQube Scanner 2.8+
    def scannerHome = tool 'SonarQube Scanner 2.8';
    withSonarQubeEnv('SonarQube 5.6.4') {
      sh "${scannerHome}/bin/sonar-scanner"
    }
    

Current Versions of our tools

  • Our Jenkins has the version 2.2

  • Our SonarQube Server has the version 5.6.4

The SonarQube Server run fine. We can analyzing our code over a local scanner.

回答1:

I was trying to test with sonarqube 2.5 plugin but keep getting a different serialization error but have tested the below code which works fine and is without "withSonarQubeEnv" just in case you are looking for alternative:

stage('SonarQube analysis')
// requires SonarQube Scanner 2.8+
def scannerHome = tool 'SonarQube Scanner 2.8';
sh "${scannerHome}/bin/sonar-scanner"

PS: I'll try to test with sonarqube 2.5 plugin and let you know if I find something.