How to use sonarcloud from local cli

Hello, I plan to use sonarcloud to run the analysis manually from the local terminal, without using any CI, by using some commands. Could you please guide me on how to run the sonarcloud analysis using the native cli and what commands I need to use?

Hi @teja14312 ,

did you already check our scanner overview page? you can scan your source code without a CI system but the commands depend on the language and build system you are using. for example if you build your java project with gradle, you can integrate a sonarcloud scan with the sonar-scanner for gradle. If you are using go, you can use the generic sonar-scanner-cli etc.

in the long run you will benefit from sonarcloud the most if you use a CI/CD System. a very easy one would be GitHub Actions (if your code is on where there is a ready to use sonarcloud action already.

hope that helps

It says I need to provide sonar.login and sonar.password when I’m trying to run a Project Analysis, even though I am using a token it throws the same error. Could you provide some examples?

sure. this is an example with the sonar-scanner-cli, assuming it is installed and available in your $PATH

sonar-scanner \
  -Dsonar.organization=<YOUR ORGANISATION> \
  -Dsonar.projectKey=<YOUR PROJECT KEY> \
  -Dsonar.sources=<PATH TO SOURCES> \ \
  -Dsonar.login=<YOUR TOKEN>

we also have a github repository with more examples here.

Yes,I specified these parameters even though I’m not able to generate the report on sonar cloud?

Can you describe in detail what exactly you are trying to achieve and the steps that you did in order to get there? the commands work if your environment and setup is as expected. If something is different there, you might need a different scanner or provide additional configuration (see examples repo in my previous post)

I followed the procedures you suggested, but when I run the same project on sonarqube, I receive accurate findings, i.e. line of codes were around 10k, but when I run the same project using the sonar cloud from a local terminal, I get the analysis but the line of code is only 500???

can you share some logs and the SQ version that you are comparing the results with? the language analyzers in SQ are in a different version that the once that are provided by SC

how did you exclude them and what is the primary language that you try to analyze? this looks like it is not meant to be ran with the generic scanner. you can use the same scanner that you were using for sonarqube, just reconfigure it to point to your org/project on sonarcloud.

I’m using for Swift and it throws error like java.nio.file.nosuchfileexception and list of errors at com.sonar.cpp.plugin.buildwrapperjsonreader.readcapture(

Okay if you are using swift you should check out this example: sonar-scanning-examples/swift-coverage at master · SonarSource/sonar-scanning-examples · GitHub