admin管理员组

文章数量:1401233

I would like to have Sonar scanner running on my project when it builds in jenkins.

Something like this,

Most of the tutorials seem to only address this process from a Java perspective, So I am wondering how this can be done if at all.

I am doing some of the work out of a Jenkinsfile in my project:

stage('SonarQube') {
  environment {
    scannerHome = tool 'SonarQubeScanner'
  }
  steps {
    withSonarQubeEnv('SonarQubeScanner') {
      sh "${scannerHome}/bin/sonar-scanner"
    }
  }
}

I used the following link to get the project in SonarQube: /

I get a couple different errors when the scan tries to run during the Jenkins Build:

Error 1

Could not find executable in "/opt/app-root/src/.sonar/native-sonar-scanner".

Proceed with download of the platform binaries for SonarScanner...
 Creating /opt/app-root/src/.sonar/native-sonar-scanner

Downloading from .4.0.2170-linux.zip

(executable will be saved in cache folder: /opt/app-root/src/.sonar/native-sonar-scanner)

ERROR: impossible to download and extract binary: connect ETIMEDOUT 

Error 2

ERROR: Failed to download .4.0.2170-linux.zip from agent; will retry from master

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

I would like to have Sonar scanner running on my project when it builds in jenkins.

Something like this,

Most of the tutorials seem to only address this process from a Java perspective, So I am wondering how this can be done if at all.

I am doing some of the work out of a Jenkinsfile in my project:

stage('SonarQube') {
  environment {
    scannerHome = tool 'SonarQubeScanner'
  }
  steps {
    withSonarQubeEnv('SonarQubeScanner') {
      sh "${scannerHome}/bin/sonar-scanner"
    }
  }
}

I used the following link to get the project in SonarQube: https://nickkorbel./2020/02/05/configuring-sonar-with-a-create-react-app-in-typescript/

I get a couple different errors when the scan tries to run during the Jenkins Build:

Error 1

Could not find executable in "/opt/app-root/src/.sonar/native-sonar-scanner".

Proceed with download of the platform binaries for SonarScanner...
 Creating /opt/app-root/src/.sonar/native-sonar-scanner

Downloading from https://binaries.sonarsource./Distribution/sonar-scanner-cli/sonar-scanner-cli-4.4.0.2170-linux.zip

(executable will be saved in cache folder: /opt/app-root/src/.sonar/native-sonar-scanner)

ERROR: impossible to download and extract binary: connect ETIMEDOUT 

Error 2

ERROR: Failed to download https://binaries.sonarsource./Distribution/sonar-scanner-cli/sonar-scanner-cli-4.4.0.2170-linux.zip from agent; will retry from master

SonarQube installation defined in this job (sonarqube) does not match any configured installation. Number of installations that can be configured: 1.
Share Improve this question edited Jul 13, 2020 at 13:22 Jub10 asked Jul 13, 2020 at 13:16 Jub10Jub10 3132 gold badges3 silver badges20 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Error 2 is about missing integration with sonarqube server.

Full install of sonarqube:

  1. Install SonarQube server
  2. Install the SonarQube Scanner plugin for Jenkins.
  3. Configure your SonarQube server(s):
  • Log into Jenkins as an administrator and go to Manage Jenkins > Configure System.
  • Scroll down to the SonarQube configuration section, click Add SonarQube, and add the values you're prompted for.
  • The server authentication token should be created as a 'Secret Text' credential.

withSonarQubeEnv('SonarQubeScanner') - "SonarQubeScanner" means the name of the Sonarqube server from step 3.

In the pipeline you should pass parameters for sonar-scanner tool, for example:

stage('SonarQube analysis') {
        environment {
            scannerHome = tool 'SonarQube_4.3.0'
        }
        steps {
            withSonarQubeEnv('Your Sonar Server Name here') {
                sh '''
                ${scannerHome}/bin/sonar-scanner \
                -D sonar.projectKey=YOUR_PROJECT_KEY_HERE \
                -D sonar.projectName=YOUR_PROJECT_NAME_HERE \
                -D sonar.projectVersion=YOUR_PROJECT_VERSION_HERE \
                -D sonar.languages=js,ts \  // DEPRECATED, do not use this option
                -D sonar.sources=./src \
                -D sonar.test.inclusions=YOUR_INCLUSIONS_HERE \
                -D sonar.exclusions=YOUR_EXCLUSIONS_HERE
                '''
            }
        }
    }

Suppose Error 1 will be fixed after you fix Error 2. Take a look at official documentation here

In my case any ways to init scannerHome var were unsuccessful. So I did it my way:

stage("SonarQube analysis") {
    steps {
        script {
            withSonarQubeEnv('SonarQube Server') {
                sh '''
                  ${JENKINS_HOME}/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner/bin/sonar-scanner \
                   -Dsonar.host.url=URL_TO_SONAR \
                   -Dsonar.login=SONAR_TOKEN \
                   -Dsonar.projectKey=PROJECT_KEY \
                   -Dsonar.projectName=PROJECT_NAME
                '''
            }
        }
    }
}

本文标签: javascriptHow to setup SonarQube scanner in jenkins for a jstsreact projectStack Overflow