简体   繁体   English

SonarQube 扫描仪在找不到 Jenkins 管道命令中失败

[英]SonarQube Scanner fails in a Jenkins pipeline command not found

I'd like to run SonarQube Scanner from a Jenkins pipeline and I followed the documentation.我想从 Jenkins 管道运行 SonarQube Scanner,并按照文档进行操作。

Regarding the error, it seems that the scanner is present but some commands are not found.关于该错误,似乎存在扫描仪但未找到某些命令。 My jenkins instance runs in local.我的詹金斯实例在本地运行。

error message :错误信息 :

 + /usr/local/bin/sonar-scanner
/usr/local/Cellar/sonar-scanner/4.6.2.2472_1/libexec/bin/sonar-scanner: line 17: dirname: command not found
/usr/local/Cellar/sonar-scanner/4.6.2.2472_1/libexec/bin/sonar-scanner: line 18: basename: command not found
/usr/local/Cellar/sonar-scanner/4.6.2.2472_1/libexec/bin/sonar-scanner: line 28: dirname: command not found
File does not exist: //lib/sonar-scanner-cli-4.6.2.2472.jar
'/' does not point to a valid installation directory: /
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

script pipeline :脚本管道:

    node {
    stage('Preparation') {
        try{
            
        // Clone Project from bitbucket
        git url: 'https://test@bitbucket.org/test/test.git'
        
        }catch(err){
            echo err
        }
    }
    
stage('Sonarqube') {
  
      sh '/usr/local/bin/sonar-scanner'

       
}
    
    stage('end') {  
     echo "Success" 
    }
}

You can use a docker image in your pipeline to have acces to the sonar-scanner, like this in scripted pipeline :您可以在管道中使用 docker 映像来访问声纳扫描器,就像在脚本化管道中一样:

node {
    stage('Preparation') {
        try {
            // Clone Project from bitbucket
            //git url: 'https://test@bitbucket.org/test/test.git'
        } catch(err) {
            echo err
        }
    }
    
    docker.image('sonarsource/sonar-scanner-cli').inside {
        stage('Sonarqube') {
            sh 'sonar-scanner'
        }
    }
    
    stage('end') {  
     echo "Success" 
    }
}

If you don't have docker installed, you can have a look to the scanner documentation to install it during your pipelin or in jenkins itself.如果您没有安装 docker,您可以查看扫描仪文档以在您的流水线或 jenkins 中安装它。

I face the same issue in Bitbucket that can be resolved by this.我在 Bitbucket 中遇到了同样的问题,可以通过这个解决。

First, check the path where sonar-scanner is installed.首先,检查sonar-scanner的安装路径。 You can run the command which sonar-scanner to find out its location on the PATH , eg:您可以运行which sonar-scanner的命令来找出它在PATH上的位置,例如:

/opt/sonar-scanner/bin/sonar-scanner

Then use the full path to sonar-scanner when executing it.然后在执行时使用sonar-scanner的完整路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM