Execute SonarQube Scanner within Jenkins 2 Pipeline

后端 未结 3 760
花落未央
花落未央 2020-12-10 09:12

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 sc

相关标签:
3条回答
  • 2020-12-10 09:41
    env.sonarHome= tool name: 'scanner-2.4', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
    
    withSonarQubeEnv('sonar.installation') { // from SonarQube servers > name
      sh "${sonarHome}/bin/sonar-runner -Dsonar.host.url=${SONAR_HOST_URL}  -Dsonar.login=${SONAR_AUTH_TOKEN}    -Dsonar.projectName=xxx -Dsonar.projectVersion=xxx -Dsonar.projectKey=xxx -Dsonar.sources=."
    
    }
    
    0 讨论(0)
  • 2020-12-10 09:58

    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=..."
    
    0 讨论(0)
  • 2020-12-10 09:58

    You can, instead, just provide the full path to ur sonar-runner. As shown in the below snippet.

    def runSonarScan(sonar_url){
        withEnv(['SONAR_HOST=' + sonar_url]) {
            sh '''
            $/opt/sonarqube/sonar-runner-2.4/bin/sonar-runner -e -Dsonar.host.url=${SONAR_HOST}
            '''
        }
    }
    

    If you have specific sonar properties add them as a sonar-project.properties file as shown here Sonar Project Properties

    0 讨论(0)
提交回复
热议问题