Hi, I’m running sonarcloud on monorepo hosted in Github. I run sonar-scanner in Drone CI using the drone plugin. When drone is running on master I call the following command: sonar-scanner -Dsonar.login=$SONAR_TOKEN -Dsonar.host.url=$SONAR_HOST
and when I’m running on PR branch I run the following: sonar-scanner -Dsonar.login=$SONAR_TOKEN -Dsonar.host.url=$SONAR_HOST -Dsonar.pullrequest.key=$DRONE_PULL_REQUEST -Dsonar.pullrequest.branch="$(git branch --show-current)" -Dsonar.pullrequest.base=master
My issue is that every analysis on PR has 0 new lines and contains no new code. In each PR the sonarcloud quality check is properly displayed. What am I doing wrong?
Welcome to the community, sorry for the late answer!
It would be good to check what are the changed files in the pull request. This is computed based on the equivalent of this command:
git diff --name-only origin/master...HEAD
Try to execute this command right before the sonar-scanner command above, review the list of files that it prints, and see if it matches what you expect.
Do you set sonar.sources or other parameters to exclude or include files from the analysis? Those settings can also play a part in removing some of the analysis results.
Hi, thank you very much for your answer and suggestions.
Regarding the sources: I’m setting sources and test folders for each of the monorepo’s services using the sonar-project.properties file. The settings usually look like this:
sonar.sources=src
sonar.tests=spec
Regarding the git diff: The command you sent when called right before the sonar-scanner returns the expected output. However note that the paths returned are relative to the repo root but sonar-scanner command is called in the service subdirectory.
I think that should not be a problem. (I verified in a simple test.)
Please activate debug mode by passing -X to the scanner command, and find in the output any of the files that you expect should be part of the results on SonarCloud.
Do you mean that the Code tab of the pull request’s page on SonarCloud is empty? Or do you mean something else?
Can you share the full content of the sonar-project.properties file? Just to check if there might other settings that could interfere with the results.
So I tried running it with the -X switch and it appears that the proper files are processed. I’m seeing lines similar to the following:
11:34:01.602 DEBUG: '<PATH_TO_THE_FILE>' indexed with language 'ts'
Should I look for other information in the -X run output?
Regarding the 0 lines: When I open the sonarcloud PR analysis through the sonarcloud quality check in my PR on github the Code tab is empty and also in the Summary in the top left corner it says 0 New Lines.
I managed to fix this. One issue was sending wrong PR branch and also I added custom clone step to my drone config. The clone step did the trick but not sure why.