Reputation:
I have paid account in Sonarcloud and Gitlab CI for automation, I use Visual Studio with integrated SonarLint for C#. Sometimes I want to run analyzing manually from VS and not using Gitlab runner every time. Is there a way to bypass pipeline? The reason is that I have limitations for runner minutes and I want to make commit and run pipeline only when I cleanup code warnings from SonarLint.
Upvotes: 3
Views: 9566
Reputation: 6629
You can trigger a SonarCloud analysis locally using SonarScanner:
The MSBuild option looks something like this:
SonarScanner.MSBuild.exe begin /k:"project-key"
MSBuild.exe <path to solution.sln> /t:Rebuild
SonarScanner.MSBuild.exe end
The .NET Core global tool looks like this:
dotnet tool install --global dotnet-sonarscanner
dotnet sonarscanner begin /k:"project-key" /d:sonar.login="myAuthenticationToken"
dotnet build <path to solution.sln>
dotnet sonarscanner end /d:sonar.login="myAuthenticationToken"
Since You need to call SonarScanner before and after a build. you can integrate the SonarScanner commands in Visual Studio using Build Events. Add the commands to PreBuildEvent.bat
and PostBuildEvent.bat
to run the analysis automatically every time you build. If you don't want to run SonarScanner every time you build, create a new custom build configuration (e.g. Debug, Release, Analyze).
You will need to generate a private token for your project key in SonarCloud. The final report will also be available in that project when it is ready.
If you don't need to update SonarCloud and just want to view the code analysis results, you can use SonarLint Visual Studio extension. You can connect SonarLint with SonarCloud to download your common configuration using a feature called Connected Mode.
Connected mode does not push issues to the server. Rather, its purpose is to configure the IDE so that it uses the same settings as the server.
A summary of instructions (see Connected Mode for details):
SonarLint will then fetch the required settings from the server and create local configuration files
Your code will be analyzed live (as you type), or you can run a full code analysis as follows:
Upvotes: 3