SonarQube : nUnit's results are not displayed - jenkins

I'm using SonarQube and Jenkins. In Jenkins, I check the unit tests with nUnit and the coverage with opencover. The opencover's report is displayed in Sonar but the nunit's report is not. The Unit Tests count is not even displayed in the home page of the project.
Here is what I do :
Build my VisualStudio project with MSBuild
Run nunit and opencover with a batch command line
Run SonarQube scanner's analysis
Package the project
The Step 2's command line :
MKDIR "%WORKSPACE%\reports"
MKDIR "%WORKSPACE%\reports-history"
SET COV_PTH="D:\Programmes\opencover.4.5.3522"
SET TOOL_PATH="D:\Programmes\NUnit-2.6.4"
SET RPT_PATH="D:\Programmes\ReportGenerator"
copy src\Foo.Bar.Tests\app.config build\Foo.Bar.Tests.dll.config
%COV_PTH%\OpenCover.Console.exe "-filter:+[Foo.Bar*]* -[Foo.Bar.Tests]* -[Foo.Bar.Service]* -[Foo.Bar.Domain]* -[Foo.Bar.Dal]Foo.Bar.Dal.Dao.* -[Foo.Bar.Controller]Foo.Bar.Controller.*Comparer -[Foo.Bar.Controller]Foo.Bar.Controller.External.*" -register "-target:%TOOL_PATH%\bin\nunit-console.exe" -targetargs:"build\Foo.Bar.Tests.dll /noshadow /result=reports\TestResult.xml" -output:reports\opencovertests.xml
%RPT_PATH%\ReportGenerator.exe "-reports:reports\opencovertests.xml" "-targetdir:reports-ReportGenerator" "-historydir:reports-history"
The Step 3's parameters :
sonar.projectKey=FooBar
sonar.projectName=FooBar
sonar.projectVersion=%SVN_REVISION%
sonar.sources=src/Foo.Bar.Controller, src/Foo.Bar.Dal, src/Foo.Bar.Domain, src/Foo.Bar.Fichier, src/Foo.Bar.Generation, src/Foo.Bar.Reporting, src/Foo.Bar.Service, src/Foo.Bar.Web
sonar.binaries=Build/Foo.Bar.Controller.dll, Build/Foo.Bar.Dal.dll, Build/Foo.Bar.Domain.dll, Build/Foo.Bar.Service.dll, Build/Foo.Bar.Fichier.exe, Build/Foo.Bar.Generation.exe, Build/Foo.Bar.Reporting.exe
sonar.tests=src/Foo.Bar.Tests
sonar.cs.opencover.reportsPaths=reports/opencovertests.xml
sonar.cs.nunit.reportsPaths=reports/TestResult.xml
EDIT
I also tried the following process (same results) :
Prepare SonarQube scanner's analysis
Build my VisualStudio project with MSBuild
Run nunit and opencover with a batch command line
End SonarQube scanner's analysis
Package the project
END EDIT
The nUnit's report is well generated in workspace/reports/TestResult.xml.
I tested the analysis generation by command line and via the sonarqube plugin for jenkins. I got the same results.
Can you see anything wrong?
Is there any SonarQube's logs that I could checked ?
I am using Jenkins 2.10, MSBuild 12, SonarQube 5.6, SonarQube scanner for Jenkins plugin 2.4.3, opencover 4.5 and nunit 2.6.4
EDIT
I updated my config : Jenkins 2.18, MSBuild 14, SonarQube scanner for Jenkins plugin 2.4.4. Same results.
END EDIT

Take a look at: SonarQube documentation: Unit Test Execution Results Import (C#, VB.NET)
It says:
Drilldown on Test Execution Results is not supported
My understanding is that you can only see the results (number of Tests passing, errors, etc) but not detail from the tests.
You also ask about Logs. You have:
Jenkins Job log
SonarQube Background tasks: Login as Admin -> Administration -> Projects -> Background tasks -> far right of each execution ---> http://docs.sonarqube.org/display/SONAR/Background+Tasks
SonarQube logs: sonar_install_directory\logs

Related

TFS 2015 No agent can be found with following capabilities: msbuild, java, sonar qube

I've succeeded build with TFS 2015 Using MSbuild task. Now I've added Sonar qube tasks (SonarQube for MSBuild - Begin Analysis & End Analysis), find the Sonarqube settings below:
1. What is the Project key & how do we get it? I just gave Project Name as key.
Immediately on build trigger threw error/warning:
There are issues with the request or definition that may prevent the
build from running:No agent could be found with the following
capabilities: msbuild, java, msbuild, java. Queue the build anyway?
On Trigger Build further, Build failed with following error
No agent found in pool which satisfies the specified demands:
msbuild
java
msbuild
msbuild java Agent.Version -gtVersion 1.94.0
On cross-checking, i see that under General section in Build definition : Demand for MSBuild & java exists.
2. Am i correct or missing anything/settings?
I've configured Service Endpoint for SonarQube also. Find the screen shot below:
Please suggest on my error & queries highlighted.
When adding new task which required agent capabilities you need to add it to the agent.
The capabilities must be installed on the build servers where the agents are located.
UPDATE:
I just installed sonar qube on my test environment.
I got the same exception as you did, fixed it by installing java and msbuild .
Check,if those capabilities exists under your agent :

Sonarqube with dotnet core works fine on command line but not from Jenkins

I'm trying to launch Sonarqube on a .NET Core 2.0 solution from Jenkins using SOnarQube MsBuild on Windows.
It works fine when i execute the following script from Jenkins workspace:
C:\SonarQube\bin\MSBuild.SonarQube.Runner.exe begin /k:XXXX.Campaigns /n:CI /v: /d:sonar.host.url=http://x.x.x.x:9000 /d:sonar.verbose=true /d:sonar.projectBaseDir="C:\Program Files (x86)\Jenkins\workspace\CI"
dotnet clean
dotnet build
C:\SonarQube\bin\MSBuild.SonarQube.Runner.exe end
But when i execute the same command from Jenkins, i got this message:
The SonarQube MSBuild integration failed: SonarQube was
unable to collect the required information about your projects.
Possible causes:
The project has not been built - the project must be built in
between the begin and end steps.
An unsupported version of MSBuild
has been used to build the project. Currently MSBuild 14.0 upwards
The begin, build or end steps have not all been
launched from the same folder
I use Jenkins 2.46.2 - MSBuild 15 - Sonarqube 6.7 & Sonar MsBuild 4.0.2.892. I tried using Jenkins build steps, command step, command step with a script without success. On a classical .Net 4.5.2 project, it works.
Jenkins was running as local system user. I change it to a normal Windows user and it did the trick. dotnet build was not using Sonarqube dedicated targets.
Thanks you #Valeri!

How do I set Local module directory for sonar scanner for MSBuild in Jenkins?

My jenkins project does 2 checkouts, one from a framework and one from an application A that uses the framework.
I want to run a sonar scanner on application A.
I Have 6 building steps in jenkins
Execute Windows batch command : nuget.exe restore "%WORKSPACE%\Framework\branches\1.0.1.0\Framework.sln"
Execute Windows batch command : nuget.exe restore "%WORKSPACE%\AppUsingFramework\branches\v1.1.3\AppUsingFramework.sln"
Build a Visual Studio project or solution using MSBuild : build framework
SonarQube Scanner for MSBuild - Begin Analysis // HOW DO I SET THE FOLDER TO %WORKSPACE%\AppUsingFramework\branches\v1.1.3 ?
Build a Visual Studio project or solution using MSBuild : build the application
MSBuild Build File : AppUsingFramework\branches\v1.1.3\AppUsingFramework.sln
SonarQube Scanner for MSBuild - End Analysis
I get this message :
The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
Possible causes:
The project has not been built - the project must be built in between the begin and end steps
An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0 upwards are supported
The begin, build or end steps have not all been launched from the same folder
Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
So I suspect that I should specify working folder (%WORKSPACE%\AppUsingFramework\branches\v1.1.3) to sonar when I start it, how do I do that ?
I use :
Jenkins 2.60.2
SonarQube Scanner for MSBuild 3.0.1.635 (install automatically from github)
MSBuild 15
By removing the unnecessary build framework step (it's built in the app already) and by only specifiying AppUsingFramework.sln without path the sonar scan succeed.

SonarQube MSBuild integration failed - using MSBuild definition for building .Net Application

This is my first blog or query. I am very new to TFS Admin role and sonarqube tool.
We are using TFS 2013 as an ALM in our project, the project is based on .Net Application (new to .NET as well).
As per the client requirement, I am trying to integrate the "SonarQube 5.2" with the customized build process template instead of default template.
I installed the "SonarQube 5.2" on "ABC server" and my "TFS server/build agent" is on "XYZ".
I installed the SonarQube Scanner for MSBuild 2.1 on XYZ server and updated the environment variables & sonarqube runner xml accordingly.
As per the standard link I am not using default template:-http://docs.sonarqube.org/display/SCAN/From+Team+Foundation+Server+2013
and using a customized build template, which hadn't have pre/post build argument options.
So I edited in the customized build process template, added hooks for pre/post build scripts activities and updated the properties similar to the mentioned link :-
http://www.colinsalmcorner.com/post/build-script-hooks-for-tfs-2012-builds
Note: As per the above link, I didn’t update "Challenge 2 – Environment Variables" part in the process template as I am not running any powershell script only wanted to execute the MSBuild.SonarQube.Runner.exe.
Used following activity & properties within the customized process template (refer above link):
*ConvertWorkspaceItem activity, set the following properties:
• DisplayName: “Get pre-build script local path”
• Input: PreBuildScriptPath
• Result: preBuildScriptLocalPath
• Workspace: Workspace
Set the following properties in the InvokeProcess activity:
• Arguments: String.Format(" ""& '{0}' {1}"" ", prebuildScriptLocalPath, PreBuildScriptArgs)
• DisplayName: “Run pre-build script”
• FileName: “PowerShell”
• Working Directory: SourcesDirectory*
Note: Same thing done for post build script
Sequentially, I placed these pre and post script activities under "Try, Compile and Test" activity of the process template.
In the MS build definition which is using the customized process template, I am setting below values in build process parameters (location/path of runner.exe on XYZ server) :
Pre-build script path : C:\SonarQube\bin\MSBuild.SonarQube.Runner.exe
Pre-build script arguments : begin /n: /v:< project version #> /k:
Post-build script path : C:\SonarQube\bin\MSBuild.SonarQube.Runner.exe
Post-build script arguments : end
But after all these changes, my build is getting partially successful and sonarqube integration is failed with the following error:
*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*
Note: On XYZ server (TFS build server) we do have MSBuild 12.0 and build is happening under SourcesDirectory as ".sonarqube" folder is getting created within the same directory.
Also on XYZ server's command prompt (within the location of SourceDirectory or where the ApplicationName.sln is available), I ran following sonarqube commands, my analysis was successful and reports generated on Sonarqube dashboard:
- MSBuild.SonarQube.Runner begin /n:<project name> /v:< project version #> /k: <project key>
- "C:\Program Files (x86)\MSBuild\12.0\Bin\Msbuild.exe" "ApplicationName.sln" /p:Configuration=Debug /p:Platform="Any CPU"
- MSBuild.SonarQube.Runner end
Kindly go through this, it will be a great help if someone can guide me and provide some concrete explanation to resolve this.
Let me know if you need any other information.
as I read in your comment:
MSBuild.SonarQube.Runner is installed on "C:\sonarquberunner\" and
MSBuild is under
"C:\Windows\Microsoft.Net\Framework\v4.0.30319\MSBuild.exe" and my
build directory on TFS server is
"D:\data\Build\$(BuildAgentId)\$(BuildDefinitionPath)" (location of
source code for build).
You have installed MSBUILD 12, but the Build agent is calling the version 4.0
You need to modify your build process template in order to achieve that.
Find the Run MSBuild activity in your build template and set the ToolPath = “C:\Program Files (x86)\MSBuild\12.0\bin\” or the path of your MSBUILD 12
You may try to specify the /n:/k:arguments:
/k:"the project key of the SonarQube project to which the build
definition relates"
/n:"the project name of the SonarQube project"
Also, instead of Post-build script path and Post-build script arguments, try to set the Post-test script path to the full path to MSBuild.SonarQube.Runner.exe, and set the Post-test script arguments to end.
Check the screenshot below:

Unit test not showing up in SonarQube

Using Jenkins I am trying to pass the result of the Nunit task and the OpenCover task to SonarQube.
SonarQube displays properly the test coverage but there is no trace of unit test results.
Here is what I do :
Build Visual Studio project with MSBuild
Batch windows for opencover via nunit
Launch SonarQube scanner
Batch windows for deployement
Here is my actual properties for the Sonar Scanner task:
sonar.projectKey=FC
sonar.projectName=FC
sonar.projectVersion=%SVN_REVISION%
sonar.sources=src
sonar.binaries=build
sonar.exclusions=src/FC.Test/**/*.*
sonar.tests=src/FC.Test
sonar.cs.nunit.reportsPaths=TestResult.xml
sonar.cs.opencover.reportsPaths=reports/opencovertests.xml
I'm using SonarQube 5.6, Jenkins 2.10, SonarQube plugin 2.4.3, OpenCover 4.5 and Nunit 2.6.4
Is there any known problems (compatibility issues...) ?
Note that I tryed to wrap my process with the Prepare and Terminate Sonar analysis tasks but it systematicaly deletes the coverage panel. So i removed it.
EDIT 2017
I stopped doing this way. I understood that the good way to do this was using the SonarQube Scanner for MSBuild which is integrated at the Jenkins's plugin.
The coverage panel was not shown because i didn't configure my quality profiles properly.
But...
I still don't have my tests' result in Sonar.
I checked the absolute path of my report and its parsing by sonarQube : "INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=25ms". I also tryed with a .nunit file. I saw that apply a filter to opencover could help, so I did.
Do you have a clue?
Scanning C# projects requires to use the Sonar Scanner for MSBuild and follow a specific 3 steps process which I guess you don't follow for now. See doc about the 3 steps process at: http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild and http://docs.sonarqube.org/display/SCAN/From+Jenkins
Your properties look correct. Yet they shall not be provided in a sonar properties file but instead in the command line arguments of the MSBuild.SonarQube.Runner.exe begin step, for example:
MSBuild.SonarQube.Runner.exe begin <allMandatoryParameters> /d:sonar.cs.nunit.reportsPaths=TestResult.xml /d:sonar.cs.opencover.reportsPaths=reports\opencovertests.xml
Olivier

Resources