I've SonarQube 5.2 with msbuild runner 1.0.2 running fine and pushing results to server. All fine.
I would like to be able to generate reports of issues either as a result of runner or from SonarQube web. How can I do this?
Pass /d:sonar.analysis.mode=preview /d:sonar.issuesReport.html.enable=true to MSBuild.SonarQube.Runner.exe while issuing begin command
MSBuild.SonarQube.Runner.exe begin /k:"codequalitysample" /n:"Code Quality Sample" /v:"1.0" /d:sonar.resharper.cs.reportPath="%CD%\ResharperInspectionResults.xml" /d:sonar.resharper.solutionFile="%CD%\CodeQualitySample.sln" /d:sonar.analysis.mode=preview /d:sonar.issuesReport.html.enable=true
msbuild /t:Rebuild "%CD%\CodeQualitySample.sln"
"%rctdir%\inspectcode.exe" /output="%CD%\ResharperInspectionResults.xml" "%CD%\CodeQualitySample.sln"
MSBuild.SonarQube.Runner.exe end
Related
I'm having issues trying to execute the SonarQube Scanner. The begin part seems to run without issues, and also the MSBuild command, but the end part fails.
1st step: I execute the following SonarQube Scanner command:
D:\workspace\MasterData>SonarQube.Scanner.MSBuild.exe begin /k:"masterdata" /n:"MasterData" /v:"1.0" /d:sonar.host.url=http: //xyz.com.br:9000/sonarqube /d:sonar.login=5773c2ca935fde42c72494a96de5a68a5b6899d1 /d:sonar.verbose=true
SonarQube Scanner for MSBuild 2.2
Default properties file was found at D:\sonar-scanner-msbuild-2.2.0.24\SonarQube.Analysis.xml
Loading analysis properties from D:\sonar-scanner-msbuild-2.2.0.24\SonarQube.Analysis.xml
sonar.verbose=true was specified - setting the log verbosity to 'Debug'
Pre-processing started.
Preparing working directories...
Using environment variables to determine the download directory...
Removing the existing directory: D:\workspace\MasterData\.sonarqube
Creating directory: D:\workspace\MasterData\.sonarqube
SonarQube server URL: http: //xyz.com.br:9000/sonarqube
SonarQube Scanner for MSBuild 2.2
15:11:10.032 Loading analysis properties from D:\sonar-scanner-msbuild-2.2
.0.24\SonarQube.Analysis.xml
15:11:10.04 sonar.verbose=true was specified - setting the log verbosity to 'Debug'
15:11:10.042 Updating build integration targets...
15:11:10.045 Installed SonarQube.Integration.ImportBefore.targets to C:\Users\AppData\Local\Microsoft\MSBuild\14.0\Microsoft.Common.targets\ImportBefore
15:11:10.046 Installed SonarQube.Integration.ImportBefore.targets to C:\Users\f
g009adm\AppData\Local\Microsoft\MSBuild\12.0\Microsoft.Common.targets\ImportBefore
15:11:10.048 Installed SonarQube.Integration.targets to D:\workspace\MasterData\.sonarqube\bin\targets
15:11:10.049 Creating config and output folders...
15:11:10.049 Creating directory: D:\workspace\MasterData\.sonarqube\conf
15:11:10.049 Creating directory: D:\workspace\MasterData\.sonarqube\out
15:11:10.055 Fetching analysis configuration settings...
15:11:10.062 Fetching properties for project 'masterdata' from http: //xyz.com.br:9000/sonarqube/api/properties?resource=masterdata...
15:11:10.062 Downloading from http: //xyz.com.br:9000/sonarqube/api/properties?resource=masterdata...
15:11:10.214 Downloading from http: //xyz.com.br:9000/sonarqube/api/updatecenter/installed_plugins...
15:11:10.239 Fetching quality profile for project 'masterdata' from http: //xyz.com.br:9000/sonarqube/api/qualityprofiles/search?projectKey=masterdata...
15:11:10.24 Downloading from http: //xyz.com.br:9000/sonarqube/api/qu
alityprofiles/search?projectKey=masterdata...
15:11:10.272 Downloading from http: //xyz.com.br:9000/sonarqube/api/rules/search?f=repo,name,severity,lang,internalKey,templateKey,params,actives&ps=
500&activation=true&qprofile=cs-sbs-cs-default-201410-86215&p=1...
15:11:10.451 Downloading from http: //xyz.com.br:9000/sonarqube/api/rules/search?f=internalKey&ps=500&activation=false&qprofile=cs-sbs-cs-default-201410-86215&p=1&languages=cs...
15:11:10.506 Generating rulesets...
15:11:10.506 Generating the FxCop ruleset: D:\workspace\MasterData\.sonarq
ube\conf\SonarQubeFxCop-cs.ruleset
15:11:10.518 Writing Roslyn generated ruleset to D:\workspace\MasterData\.sonarqube\conf\SonarQubeRoslyn-cs.ruleset...
15:11:10.534 Writing Roslyn analyzer additional file to D:\workspace\MasterData\.sonarqube\conf\cs\SonarLint.xml...
15:11:10.536 Provisioning analyzer assemblies for cs...
15:11:10.538 Installing required Roslyn analyzers...
15:11:10.538 Local analyzer cache: C:\Users\fg009adm\AppData\Local\Temp\7\.sonarqube\.static
15:11:10.538 Processing plugin: csharp version 1.23.0.1828
15:11:10.54 Cache hit: using plugin files from C:\Users\AppData\Local\Temp\7\.sonarqube\.static\csharp_1.23.0.1828\SonarAnalyzer-1.23.0.1828.zip
15:11:10.566 Pre-processing succeeded.
2nd step: I execute the following MSBuild command:
MSBuild.exe /t:Rebuild MasterDataWebServices.sln
Since the MSBuild log is quite big, I will not provide it here. There is a Build succeeded message, with 5 warnings and 0 errors.
3rd step: I execute the following SonarQube Scanner end command:
D:\workspace\MasterData>SonarQube.Scanner.MSBuild.exe end
SonarQube Scanner for MSBuild 2.2
Default properties file was found at D:\sonar-scanner-msbuild-2.2.0.24\SonarQube.Analysis.xml
Loading analysis properties from D:\sbs1\sonar-scanner-msbuild-2.2.0.24\SonarQube.Analysis.xml
Post-processing started.
SonarQube Scanner for MSBuild 2.2
14:25:22.961 Loading the SonarQube analysis config from D:\workspace\MasterData\.sonarqube\conf\SonarQubeAnalysisConfig.xml
14:25:22.964 Not running under TeamBuild
14:25:22.964 Analysis base directory: D:\workspace\MasterData\.sonarqube
Build directory:
Bin directory: D:\workspace\MasterData\.sonarqube\bin
Config directory: D:\workspace\MasterData\.sonarqube\conf
Output directory: D:\workspace\MasterData\.sonarqube\out
Config file: D:\workspace\MasterData\.sonarqube\conf\SonarQubeAnalysisConfig.xml
Generating SonarQube project properties file to D:\workspace\MasterData\.sonarqube\out\sonar-project.properties
The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
Possible causes:
1. The project has not been built - the project must be built in between the begin and end steps
2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 12.0 upwards are supported
3. The begin, build or end steps have not all been launched from the same folder
Writing processing summary to D:\workspace\MasterData\.sonarqube\out\ProjectInfo.log
Generation of the sonar-properties file failed. Unable to complete SonarQube ana
lysis.
14:25:22.988 Creating a summary markdown file...
14:25:22.989 Post-processing failed. Exit code: 1
I was facing the same problem. In my case I installed corresponding MSBuild version required by my version of Sonar and it worked just fine.
My SonarScanner required version 14.0 or upwards of MSBuild, then I downloaded Microsoft Build Tools 2015.
In your case I believe it this version will work too and if not you can try this version more specifically.
Hope it helps.
I'm facig some issues with SonarQube integration in TeamCity with MSBuild.
Basically our nightly build using SonarQube is split into 5 steps:
1 - SonarQube Initialization
MSBuild.SonarQube.Runner.exe begin
/k:"tsmm-%sonar.project%"
/n:"%sonar.project%"
/v:"%sonar.project.version%"
/d:sonar.host.url="%sonar.host.url%"
/d:sonar.cs.dotcover.reportsPaths="coverage-report.html"
/d:sonar.cs.nunit.reportsPaths="nunit-results.xml"
/d:sonar.verbose=true
/d:sonar.jdbc.username="%sonar.jdbc.username%"
/d:sonar.jdbc.password="%sonar.jdbc.password%"
/d:sonar.jdbc.url="%sonar.jdbc.url%"
2 - Muggets restauration
3 - MSBuild
4 - Tests via NUnit
5 - Result publication to SonarQube
MSBuild.SonarQube.Runner.exe end
/d:sonar.scm.disabled=true
/d:sonar.jdbc.username="%sonar.jdbc.username%"
/d:sonar.jdbc.password="%sonar.jdbc.password%"
When the TeamCity is running the build definition above, everything is going fine until it reach the step no. 5 as stated in the build log:
Step 5/5: Publish to SonarQube (Command Line)
ERROR: Error during Sonar runner execution
org.sonar.runner.impl.RunnerException: Unable to execute Sonar
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:91)
...
Caused by: org.sonar.api.utils.SonarException: SCM URL should be provided. Please review "sonar.scm.url" parameter (or the <scm> section of pom.xml if you are using Maven).
I went through different resources including the official one there: http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild
But could not manage to find out any proper explanation, I also tried to disable the scm support as mentioned on that page: http://docs.sonarqube.org/display/SONAR/SCM+support
by adding /d:sonar.scm.disabled=true to the step 1 but it does not change anything.
The sonar.jdbc.* properties are only for older versions of SonarQube and if you are on a newer than 5.4, you should not set them.
To authenticate to SonarQube you need to use the sonar.login and sonar.password properties, as described in the article below:
http://docs.sonarqube.org/display/SCAN/From+the+Command+Line#FromtheCommandLine-Analyzeaproject
In all cases, if you have older SonarQube, I would strongly recommend upgrading to the LTS (long term support) version:
https://www.sonarqube.org/downloads/
I'm trying out SonarQube using the new MSBuild SonarQube Runner v1.0.
The Pre-processing works fine
E:\sonarQube\MSBuild.SonarQube.Runner-1.0>MSBuild.SonarQube.Runner.exe begin /k:"MyKey" /n:"MyProject" /v:"1.0"
.......
Process returned exit code 0
Pre-processing succeeded.
Then MSBuild works
E:\sonarQube\WebApplication2013>msbuild
Microsoft (R) Build Engine version 4.0.30319.34209
[Microsoft .NET Framework, version 4.0.30319.34209]
Copyright (C) Microsoft Corporation. All rights reserved.
........
Done Building Project "E:\sonarQube\WebApplication2013\WebApplication2013.sln" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.51
While end command following error gets generated
E:\sonarQube\MSBuild.SonarQube.Runner-1.0>MSBuild.SonarQube.Runner.exe end
.......
6:35:10 PM Generating SonarQube project properties file to E:\sonarQube\MSBuild.SonarQube.Runner-1.0\.sonarqube\out\sonar-project.properties
6:35:10 PM No ProjectInfo.xml files were found. Check that the analysis targets are referenced by the MSBuild projects being built.
6:35:10 PM Writing processing summary to E:\sonarQube\MSBuild.SonarQube.Runner-1.0\.sonarqube\out\ProjectInfo.log
6:35:10 PM Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
6:35:10 PM Creating a summary markdown file...
Process returned exit code 1
Post-processing failed. Exit code: 1
Required your assistance
As pointed out by duncanpMS's comment, you need to run all the 3 commands from the folder of the project you want to analyze.
Here is how:
cd E:\sonarQube\WebApplication2013
E:\sonarQube\MSBuild.SonarQube.Runner-1.0\MSBuild.SonarQube.Runner.exe begin /k:"MyKey" /n:"MyProject" /v:"1.0"
msbuild /t:rebuild
E:\sonarQube\MSBuild.SonarQube.Runner-1.0\MSBuild.SonarQube.Runner.exe end
You can add E:\sonarQube\MSBuild.SonarQube.Runner-1.0 to your %PATH% environment variable so that you can simply type MSBuild.SonarQube.Runner.exe instead of the full path from the command line when you analyze projects.
You need msbuild version 12 or version 14. If you have VS2013 , Msbuild version 12 comes with it. If you have VS2015, Msbuild version 14 comes with it.
If you don't have , download Microsoft Build Tools 2013 or 2015.
Run Msbuild -version to verify the version before running the 3 commands sequentially in the solution folder.
I have written a build script using psake which I run in Teamcity.
I have Teamcity 6.0, so I run psake from a .cmd, but I don't think that changes anything.
Everything is working fine, but I have two problems.
Nunit isn't communicating with Teamcity so when a test fails, Teamcity says everything is ok.
MsBuild behaves the same. Even though the build fails, Teamcity reports success.
I would like to know how get Teamcity to detect these failures.
Here is my example script: https://github.com/MikeEast/BuildTests/blob/master/build/build.ps1
You will probably need to notify Teamcity yourself via its simple but elegant build status notification system.
For example, you could output the following message to stdout during your powershell script.
##teamcity[buildStatus status='FAILURE' text='Some error message']
The way I have got TeamCity working (with TeamCity version 6.5.4 I must add) is to use the TeamCity module that is provided in the psake download.
Add this to your script:
...
Import-Module "$build_dir\psake\teamcity.psm1"
#Tasks here
...
Remove-Module teamcity
#End Of File
I have a build folder that I have put the module in so that all my builds can access it.
Then it worked out of the box.
I am not using the built in NUnit runner though, I have also put the NUNit console in my build folder and then call that with each UnitTest assembly:
Task Test -depends Build {
$testAssemblies = (get-childitem $base_dir -r -i "*UnitTests.dll" -exclude "*.config" -Name | Select-string "bin")
foreach($test_asm_name in $testAssemblies) {
$full_test_assembly_name = "$base_dir\$test_asm_name"
Exec { invoke-expression "$nunitconsole_path $full_test_assembly_name" }
}
}
we are trying to execute unit tests with MSTest from command line and publishing the results at the TFS server. The problem is that MSTest is always returning:
Publishing results of test run buildmachine#XXX-XXXXXXX 2010-12-16 11:39:13_Release_Any
CPU to http://xxxx:8080/Build/v1.0/PublishTestResultsBuildService2.asmx...
.........................................................................................
Build 'xxx>xxx>x>x>x>xxxx>xxxx>x.x.x.xxx' does not include the specified
configuration ('Release/Any CPU').
The problem is that the specified configuration should exist. We've build with the next MSBuild settings:
<ConfigurationToBuild Include="Release|Any CPU">
<FlavorToBuild>Release</FlavorToBuild>
<PlatformToBuild>Any CPU</PlatformToBuild>
</ConfigurationToBuild>
Any idea? I'm starting to be fed up with this.
The problem was that the build didn't succeeded and then MSTest couldn't publish the results. The error message could be better ...