jenkinssonarqubejenkins-pipelinesonarscanner

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.

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" 
    }
}

Solution

  • I face the same issue in Bitbucket that can be resolved by this.

    First, check the path where sonar-scanner is installed. You can run the command which sonar-scanner to find out its location on the PATH, e.g.:

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

    Then use the full path to sonar-scanner when executing it.