GitHub integration check only triggered after 2nd CI build

Hi,

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 :slight_smile:


  • Languages of the repo: Java
  • Repo URL: https://github.com/JoseLion/maybe
  • ALM: GitHub
  • CI system: Circle CI
    • Using a CircleCI context named SonarCloud were the environment variable SONAR_TOKEN is set
    • The SonarCloud cintext is used in the build step were the scanner command is triggered
  • Scanner command:
    • Using Gradle’s plugin org.sonarqube version 2.8:
      • ./gradlew sonarqube
    • Plugin configuration closure:
      sonarqube {
        properties {
          property 'sonar.projectKey', 'JoseLion_maybe'
          property 'sonar.organization', 'joselion'
          property 'sonar.host.url', 'https://sonarcloud.io'
          property 'sonar.pullrequest.provider', 'github'
          property 'sonar.junit.reportPaths', "${buildDir}/test-results/junit"
          property 'sonar.coverage.jacoco.xmlReportPaths', "${jacoco.reportsDir}/test/jacocoTestReport.xml"
        }
      }
      

Hello @JoseLion,

This is due to how CircleCI configures their builds, please see my comment on a similar post.

Hi @TomVanBraband, thank you for looking into this!

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 :slightly_frowning_face: (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.

Cheers.

Hello @JoseLion,

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.

There is a work around to run jobs only if in a pull request:

I think you should be interested

How to only run a job on a pull request in CircleCI | Ruairí’s Blog (ruarfff.com)

I will try this in circleci as a do have the same requisite as yours

1 Like