Coverage not showed for manual PR analysis in Drone CI

I am trying to analyze PRs on github manually using the scanner including the code coverage and duplications to check issues before merging to master.
I have another analysis on master using the same analysis parameters used for PR but with different parameters passed to the scanner.
I am using the latest docker image for sonarsource/sonar-scanner-cli following the documentation here

The command used is:

sonar-scanner -Dsonar.login=$SONAR_LOGIN -Dsonar.host.url=$SONAR_HOST -Dsonar.pullrequest.key=${DRONE_PULL_REQUEST} -Dsonar.pullrequest.branch=${DRONE_SOURCE_BRANCH} -Dsonar.pullrequest.base=${DRONE_TARGET_BRANCH} -Dsonar.pullrequest.provider=github -X

You’ll need to make sure your coverage reports are passed to an analysis parameter defined in our Test Coverage & Execution docs.

:warning: Why are you running analysis manually instead of automatically (say, running a build/analysis whenever a PR is raised)?

I am passing the coverage report in the sonar-project.properties and if I enable debug, sonar shows it is parsing it.
The problem is that only for PRs it does not show current branch coverage.

The more information you provide, the better. :slight_smile: Screenshots… what you expect to see (what coverage do you expect to be reported?), how it is different from what you actually see reported, etc.

I am running an analysis on Drone CI whenever a PR is raised.
Running the following command in drone sonar-scanner -Dsonar.login=$SONAR_LOGIN -Dsonar.host.url=$SONAR_HOST -Dsonar.pullrequest.key=${DRONE_PULL_REQUEST} -Dsonar.pullrequest.branch=${DRONE_SOURCE_BRANCH} -Dsonar.pullrequest.base=${DRONE_TARGET_BRANCH} -Dsonar.pullrequest.provider=github -X gives me this result:

If i run this on my machine the result is the following.

There seems to be an issue on how Drone checkouts the branch/PR, because I cannot find any other issues, the log of sonar-scanner on drone does not give me any warning.

I got the same problem, does this thread have any updates?

4 Likes

Hi, guys. I think I found the root cause of the issue.
It is indeed how Drone cloning the pull request.Since Drone checkout from the source branch and merge the target branch into it. So if SonarQube argument is set to use target as base and source as branch, then SonarQube can not find any difference between these two branches.

Just like how the origin author does: -Dsonar.pullrequest.branch=${DRONE_SOURCE_BRANCH} -Dsonar.pullrequest.base=${DRONE_TARGET_BRANCH}

I solve this issue by overwriting the logic of Drone’s clone plugin. Here is my discussion thread on Drone site: Question about clone strategy for pull request event - Drone

@Colin This leaves me to wonder what is the correct flow to do a PR analysis on CI manually? Should I do the analysis on the source branch without merging? Or do the analysis on a new branch like creating another branch from the target and merge the source branch and do the analysis?

I will be grateful for any help you can provide, thank you.

3 Likes

I have same issue, and still opened in drone forum my question about this behaviour