I recently integrated SonarCloud to a public GitHub repository with a CircleCI workflow. At first I thought it was working as expected since all tasks passed in CI ( and because I was able to see the check on PRs), but then I noticed SonarCloud check was only triggered after the second run of the CircleCI workflow, for the first the check won’t even appear in the PR.
I followed the steps on the tutorial on https://sonarcloud.io/ and I’m building with Gradle so I’m not using the official Orb, just Gradle’s plugin org.sonarqube (version 2.8) as suggested by the tutorial. Am I missing something?
I’m leaving some details of my project bellow. Thanks in advance
I see! This helped me understand a few things. I solution for this will be to enable the Only build pull requests on CircleCI, but this doesn’t work for me because CI will not run commits to long-lived branches like release, and I use those workflows for automatic deploys.
The other option is to use SonarCloud Automatic Analysis method instead, which triggers the analysis correctly on pull requests to the default branch, but it’s not supported on compiled languages like Java (also, code coverage is not supported in this method).
Is there another way to trigger the analysis whenever a pull request is opened? I was thinking maybe by adding a Webhook to GitHub but I couldn’t find any documentation on how to achieve this.
Sadly this is a feature missing from CircleCI and I can not think of a workaround using CircleCI.
Since your repository is public and you already use GitHub actions you could add a GitHub action that only runs on pullrequests and that performs the SonarCloud analysis. I see that you use Gradle so you could use this example as inspiration.