0
votes

I want run command on ser sonar-scanner or sonar-scanner -Dsonar.projectKey=node-myapp -Dsonar.sources=. -Dsonar.host.url=http://ip:9000 -Dsonar.login=key

I am trying with run .sh file in pipeline or direct scan from pipeline working on file but not work form jenkins pipeline and got error:

Error:sonar-scanner.sh: 4: sonar-scanner: not found

also ERROR: script returned exit code 127 enter image description here

1
Check what does that script returns, put "echo $?" immediately after the sonar-scanner.shMahesh_Loya
The error is because Jenkins is not able to find the path of sonar scanner. You can set the path of sonar-scanner in Global Tools configuration.Sourav Atta

1 Answers

0
votes

you have to check the current folder path and check the file path of sonar-scanner.sh run using Jenkins pipeline is the same. just check jenkins pipeline changes:

stage-1-line:

pwd

echo "sonar start"

stage2-line:

pwd

sh sonar-scanner.sh

##here, "pwd" is the same when running the Jenkins pipeline and its path of the project folder. If not then follow below step for sonar scanner:

###Running a Test Scan on SonarQube Example Projects If you’d like to just poke around with SonarQube to see what it can do, you might consider running a test scan on the SonarQube example projects. These are example projects created by the SonarQube team that contains many issues that SonarQube will then detect and report.

##Create a new working directory in your home directory, then change to the directory:

cd ~ mkdir sonar-test && cd sonar-test

Download the example project:

wget https://github.com/SonarSource/sonar-scanning-examples/archive/master.zip

Unzip the project and delete the archive file:

unzip master.zip rm master.zip

##Next, switch to the example project directory:

cd sonar-scanning-project-directory-path/myproject

###Run the scanner, passing it the token you created earlier:

sonar-scanner -D sonar.login=your_token_here

###Output: This will take a while. Once the scan is complete, you’ll see something like this on the console:

INFO: Task total time: 14.128 s INFO: ------------------------------------------------------------------------ INFO: EXECUTION SUCCESS INFO: ------------------------------------------------------------------------ INFO: Total time: 21.776s INFO: Final Memory: 17M/130M INFO: ------------------------------------------------------------------------