Hello, the command that supposed to test the code with sonar-scanner doesn’t work anymore, due to the lack of a package, I haven’t received this kind of error before, and I don’t know where to look in order to fix it.
The workflow looks like this:
AWS CodePipeline is used to fetch the source code from GitHub, after, source code is passed to CodeBuild project that runs mvn sonar:sonar in order to test the code.
ALM used: GitHub
CI system used AWS CodeBuild
Scanner command used when applicable (private details masked) mvn sonar:sonar -Dsonar.login=$LOGIN -Dsonar.host.url="https://sonarcloud.io" -Dsonar.projectKey="app-1" -Dsonar.organization="org-name"
Languages of the repository - Java
Steps to reproduce
Create a CodeBuild project, add necessary commands to buildspec.yml (download maven, sonar-scanner, etc.)
I’m surprised to see the operation prefix in the error message, while the command uses the sonar prefix.
Is there any plugin on your POM file that uses this prefix? Here is a Maven documentation about how to define a plugin prefix mapping.
To investigate further, could you please share the full logs and your pom.xml file?
Thanks for you POM file. I wasn’t able to reproduce the issue on a local build, an analysis using the same POM and some dummy code ran just fine.
Do you have the issue if you run the exact same command yourself, outside of CodeBuild?
Could you build a minimal reproducer, with the smallest POM and code, that reproduces the issue, and share it here?
Thanks for your replies.
Actually, when I ran this code locally it worked.
And when I also created a new CodeBuild project in different AWS account it also worked, now I don’t know what’s the problem.
On the impacted project, have you tried removing pieces from the POM one by one, to try to identify what piece generate the error?
If you run some other Maven goal instead of sonar:sonar, does it work?
I couldn’t reproduce the issue, even when running on CodeBuild with the build spec provided in the sample repo (thanks for that). The build succeeded and the analysis got submitted to SonarCloud.
I used a standard AWS image aws/codebuild/standard:4.0, and a Linux environment.
I notice some download errors in the logs. Since Maven caches the repository failures and do not retries them for some time, is it possible some downloads failed previously due to some transient network errors for example, making the next attempts fail too? Is the error still reproducible with the same CodeBuild project, but a clean Maven repository?
If it is possible, I would suggest deleting the CodeBuild project and re-creating it, to eliminate any weird state.
I had this error once while doing my tests, the cause was a bad SonarCloud token because I run your command blindly without any configuration. With the appropriate token, it succeeded.
Yeah, everything is set up properly, although I am storing the token in AWS Parameter Store and passing it to the CodeBuild project, trying to hardcode the token now to see if it works.
I have found out, that mvn sonar:sonar is trying to run tests using SonarQube instead of using SonarCloud
This is just a (misleading) log issue, if the URL is set to https://sonarcloud.io/, then it’s fine.
About the authorization issue, can you analyze the project outside of CodeBuild, with the same token, and confirm it works?
Would you also check the organization and project key are correct?
I tried my own CodeBuild project using default parameters and the latest commit on the public repository, it correctly submitted the analysis to SonarCloud without any error https://sonarcloud.io/summary/overall?id=app-1
Organization id is correct, project key is just the name of the project that will be created (I assume, any value passed to project key would be fine).
I have tried running it locally with the token, and it worked just fine (as well it worked just fine, when I created another CodeBuild project and passed in the SonarCloud token directly to buildspec.yml).
But once, I’ve put the token in AWS Parameter Store, it is unable to resolve(?) it, even though the parameter exists and the token value is correct, and since the token doesn’t resolve it assumes that I am using SonarQube(?).
Right now, trying to remove the environment value of parameter-store from buildspec.yml file, and see if it works without it.