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(“Build”) {
try{// copie .env sh 'cp .env.example .env' // Run `composer update` as a shell script sh 'composer update' // Clear Cache sh 'php artisan cache:clear' // clear config cache sh 'php artisan config:cache' }catch(err){ echo err } } stage("phpunit") { try{ // Run PHPUnit sh 'vendor/bin/phpunit' }catch(err){ echo err } }*/
stage(‘Sonarqube’) {
def scannerHome = tool 'sonarqube'; withSonarQubeEnv('sonarqube'){ sh "${scannerHome}/bin/sonar-scanner \ -D sonar.login=admin \ -D sonar.password=amineleboss123 \ -D sonar.projectKey=test \ -D sonar.exclusions=vendor/**,resources/**,**/*.java \ -D sonar.host.url=http://localhost:9000/" }
}
stage('end') { echo "Success" }
}