将 Jenkins 连接到 SonarQube 的问题

Problem with Connecting Jenkins to SonarQube

我有一个 Jenkins 管道,它定期从 gitlab 中拉取并构建不同的 repos,构建一个多组件平台,运行 并对其进行测试。现在我在同一台机器上安装了一个 sonarqube 服务器 (Ubuntu 18.04),我想将我的 Jenkins 连接到 sonarqube。

在詹金斯中:

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

但这失败了,下面的日志和 ERROR: script returned exit code 127:

[Pipeline] { (SonarQube analysis)
[Pipeline] script
[Pipeline] {
[Pipeline] tool
Invalid tool ID 
[Pipeline] }
[Pipeline] // script
[Pipeline] withSonarQubeEnv
Injecting SonarQube environment variables using the configuration: SonarQube
[Pipeline] {
[Pipeline] sh
+ /var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube/bin/sonar-scanner
/var/lib/jenkins/workspace/wws-full-test@tmp/durable-2c68acd1/script.sh: 1: /var/lib/jenkins/workspace/wws-full-test@tmp/durable-2c68acd1/script.sh: /var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube/bin/sonar-scanner: not found
[Pipeline] }
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeeded?
[Pipeline] // withSonarQubeEnv
[Pipeline] }
[Pipeline] // stage

当我检查磁盘上的 jenkinstools 时,sonnar 插件不存在:

$ ls /var/lib/jenkins/tools/
jenkins.plugins.nodejs.tools.NodeJSInstallation

有人可以告诉我如何将 Jenkins 连接到 sonarqube 吗?

创建并添加令牌以连接到 SonarQube。
您已在 SonarQube 中创建项目并将其用作参数:

sh """
   ${scannerHome}/bin/sonar-scanner \
   -Dsonar.projectKey=your_project_key_created_in_sonarqube_as_project \
   -Dsonar.sources=. \
"""