I am trying to use the Maven plugin to analze my project using CircleCI, but constantly receive the following error:
Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project <redacted>: Parameter 'sonar.pullrequest.branch' is mandatory for a pull request analysis
In my project’s POM I have included the following properties:
and I have also added the SONAR_TOKEN to the CircleCI context and the following step to my build:
- run:
name: Analyze on SonarCloud
command: mvn sonar:sonar
I was under the impression that the sonar.pullrequest.branch property would be set automatically by the CI system, so is there something I am missing here?
You are correct, we resolve the pull request key from the CI system. And then we use the link between the SonarCloud project and the ALM repository (GitHub, Gitlab, Bitbucket, …) to resolve the sonar.pullrequest.branch property automatically.
I suspect that the link between your SonarCloud project and your ALM might be missing. Which ALM are you using?
So I may have found something interesting. I just went to double check the SONAR_TOKEN was correct, and the token was different.
What’s weird is every time I refresh sonarcloud.io/dashboard?id=projectid it presents me with a different token. Maybe this is what is causing the problem?
You can view the list of all the tokens you generated by clicking on Profile picture > My account > Security. Each refresh of that page should add a new token to that list. Every token that was generated should still work to analyze your project.