SonarQube integration in TeamCity for .NET C# projecs - msbuild

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/

Related

How to build Jmeter 5.4.3 in Intellij?

When ever I am trying to build my JMETET 5.4.3 Source code in intellij If am getting the following errors which I am not able to resolve the errors are
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':src:dist:verifyReleaseDependencies'.
> External dependencies differ (you could update src\dist\src\dist\expected_release_jars.csv if you add -PupdateExpectedJars):
55965681 => 55965659 bytes (-22 bytes)
- 207909 log4j-1.2-api-2.17.0.jar
- 301892 log4j-api-2.17.0.jar
- 1789565 log4j-core-2.17.0.jar
- 24258 log4j-slf4j-impl-2.17.0.jar
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':src:protocol:http:test'.
> There were failing tests. See the report at: file:///E:/JMeter/apache-jmeter-5.4.3_src/apache-jmeter-5.4.3/src/protocol/http/build/reports/tests/test/index.html
Can anyone help me with this.
And is there a way in Intellij to to change your gradle version to a older version please let me know.
is there a way to build jmeter 5.4.3 in ANT rather than Gradle?
I cannot reproduce your issue:
And I strongly doubt anyone can as it would have been noticed long time ago, JMeter 5.4.3 was released in December 2021 and presumably a lot of contributors were adding their code and building/testing JMeter since then.
Personally I'm not a JMeter contributor but I need to compile it from time to time in order to amend it to my projects needs.
Just in case the steps I normally follow:
Get the required JMeter source version from Apache archives, in your case it would be https://archive.apache.org/dist/jmeter/source/apache-jmeter-5.4.3_src.zip
Verify the checksum of the downloaded archive just in case
Unpack the archive
In IntelliJ Idea open build.gradle.kts as a Project
Wait for half an hour
....
Profit?
Also be aware that according to 9 Easy Solutions for a JMeter Load Test “Out of Memory” Failure article and JMeter Best Practices you should always be using the latest version of JMeter so maybe attempt to compile JMeter 5.5 will be more successful?

Azure Devops VSTEST Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1

I am having an error in the dotnet Core step
I am trying to integrate my selenium test to Azure devops
This the logs of the dot net step
2020-10-16T03:11:25.7523865Z ##[section]Starting: Run Selenium
2020-10-16T03:11:25.8123424Z ==============================================================================
2020-10-16T03:11:25.8124047Z Task : .NET Core
2020-10-16T03:11:25.8124510Z Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
2020-10-16T03:11:25.8124816Z Version : 2.175.0
2020-10-16T03:11:25.8125178Z Author : Microsoft Corporation
2020-10-16T03:11:25.8125636Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
2020-10-16T03:11:25.8126003Z ==============================================================================
2020-10-16T03:11:27.2023831Z [command]C:\windows\system32\chcp.com 65001
2020-10-16T03:11:27.2216959Z Active code page: 65001
2020-10-16T03:11:27.2376255Z Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
2020-10-16T03:11:27.3059263Z [command]"C:\Program Files\dotnet\dotnet.exe" vstest "D:\a\r1\a\_SeleniumDemo-ASP.NET Core-CI (5)\drop\Demo2.dll" --logger:trxlogfilename=TEST.xml
2020-10-16T03:11:34.8402885Z
2020-10-16T03:11:34.9823477Z Welcome to .NET Core 3.1!
2020-10-16T03:11:34.9824051Z ---------------------
2020-10-16T03:11:34.9824560Z SDK Version: 3.1.402
2020-10-16T03:11:34.9824775Z
2020-10-16T03:11:34.9836054Z Telemetry
2020-10-16T03:11:34.9836648Z ---------
2020-10-16T03:11:34.9838913Z The .NET Core tools collect usage data in order to help us improve your experience. The data is anonymous. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.
2020-10-16T03:11:34.9840343Z
2020-10-16T03:11:34.9840938Z Read more about .NET Core CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry
2020-10-16T03:11:34.9841242Z
2020-10-16T03:11:34.9841449Z ----------------
2020-10-16T03:11:34.9841756Z Explore documentation: https://aka.ms/dotnet-docs
2020-10-16T03:11:34.9842152Z Report issues and find source on GitHub: https://github.com/dotnet/core
2020-10-16T03:11:34.9842572Z Find out what's new: https://aka.ms/dotnet-whats-new
2020-10-16T03:11:34.9842993Z Learn about the installed HTTPS developer cert: https://aka.ms/aspnet-core-https
2020-10-16T03:11:34.9843479Z Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli-docs
2020-10-16T03:11:34.9843894Z Write your first app: https://aka.ms/first-net-core-app
2020-10-16T03:11:34.9844375Z --------------------------------------------------------------------------------------
2020-10-16T03:11:39.1360071Z Microsoft (R) Test Execution Command Line Tool Version 16.7.0
2020-10-16T03:11:39.1368990Z Copyright (c) Microsoft Corporation. All rights reserved.
2020-10-16T03:11:39.1369374Z
2020-10-16T03:11:40.1936906Z The Test Logger URI 'trxlogfilename=TEST.xml' is not valid. The Test Logger will be ignored.
2020-10-16T03:11:40.7284653Z ##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
2020-10-16T03:11:40.8737953Z Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x (3.1) SDK/Runtime along with 2.1. Unless you have locked down a SDK version for your project(s), 3.x SDK might be picked up which might have breaking behavior as compared to previous versions.
2020-10-16T03:11:40.8738674Z Some commonly encountered changes are:
2020-10-16T03:11:40.8740232Z If you're using `Publish` command with -o or --Output argument, you will see that the output folder is now being created at root directory rather than Project File's directory. To learn about more such changes and troubleshoot, refer here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
2020-10-16T03:11:40.8747693Z ##[error]Dotnet command failed with non-zero exit code on the following projects : D:\a\r1\a\_SeleniumDemo-ASP.NET Core-CI (5)\drop\Demo2.dll
2020-10-16T03:11:40.8951889Z ##[section]Finishing: Run Selenium
I tried to run my code using my local machine and got not error. Please help me with Azure integration
I can reproduce this issue with the same configuration, and then I change the argument to --logger:"trx;Logfilename=TEST.trx" and it works.
Result:

NUnit tests are not restarted through VSTest in DevOps

I am using VSTest to run tests via Azure DevOps. Tests run successfully, but using the option rerun failed tests: true, an error appears during the restart phase.
NUnit 3.12.0 ;
NUnit Adapter 3.16.1.0 (Checked with 4.0.0.0)
vstest.console.exe "C:\agent2.172.2\_work\r1\a\UITest\drop\Tests.Web\bin\Release\netcoreapp3.1\Tests.Web.dll"
/Settings:"C:\agent2.172.2\_work\_temp\3utv233tymm.runsettings"
/Logger:"trx"
/TestAdapterPath:"C:\agent2.172.2\_work\r1\a\UITest\drop\Tests.Web\bin\Release\netcoreapp3.1"
/TestCaseFilter:"FullyQualifiedName=Tests.Web.Tests._5.CourierModuleTest.N1_SendingTest.Id_5_1_01_TransferToCourierModule(Chrome)|FullyQualifiedName=Tests.Web.Tests._3.IssuanceOfDocuments.InformationOnTheApplicationIdentificationOfRecipient.N2_RecipientIdentificationTest.Id_3_2_13_RegisterAddressByFiasTest(Chrome)"
NUnit Adapter 3.16.1.0: Test execution started
An exception occurred while invoking executor 'executor://nunit3testexecutor/': Incorrect format for TestCaseFilter Missing Operator '|' or '&'. Specify the correct format and try again. Note that the incorrect format can lead to no test getting executed.
How can I fix this error and successfully restart the tests in DevOps?
I tried googling for a similar issue but didn't find anything that would work. Any help is really appreciated
Here's similar discussion, according to comments from the Contributors of azure-pipelines-task repo:
1.You should update your VS and VSTest component within it to latest version since we don't support data driven tests for Rerun scenario. It will be available with VS 15.8 release and higher.
2.You should configure your VSTest task following this solution:
Recommended to give total number of your tests as input (Number of tests per batch).

SonarQube scanner for MSBuild: end MSBuild integration failed

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.

Sonar Buildbreaker Skip Failing the Build

I am using Jenkins job to build .Net project. I have added sonar analysis.
D:\Temp\tools\Scanner_MSBuild-2.2\MSBuild.SonarQube.Runner.exe begin /k:myproj /n:myproj-full /v:1.0.0 /s:D:\Temp\SonarQube.Analysis.xml
I have updated "SonarQube.Analysis.xml" with required sonar url and login credentials. But it fails with following error:
Pre-processing started.
Preparing working directories...
SonarQube Scanner for MSBuild 2.2
09:07:00.437 Updating build integration targets...
09:07:00.451 Fetching analysis configuration settings...
09:07:01.239 Could not find a file on the SonarQube server. URL: https:///api/qualityprofiles/search?defaults=true
09:07:01.239 Pre-processing failed. Exit code: 1
I tried following:
D:\Temp\tools\Scanner_MSBuild-2.2\MSBuild.SonarQube.Runner.exe begin /k:myproj /n:myproj-full /v:1.0.0 /s:D:\Temp\SonarQube.Analysis.xml -Dsonar.buildbreaker.skip=true
But it threw error that -Dsonar.buildbreaker.skip=true is not recognised command. By default buildbreaker is set to false and I am not able to make it true via commandline. SonarQube version I am using is below 5.2.
How do I fix this?
Thank you
If you're using the 'Begin Analysis' and 'End Analysis' build steps, then configuring your server URL in SonarQube.Analysis.xml won't get you far (as you've learned).
Instead, you need to configure the location of your server at the global level as described in the docs. Briefly:
Manage Jenkins > Configure System > SonarQube configuration
Add SonarQube
fill in your server info.
Then double check that that server instance is selected in your build steps (if you have only one server configured, build steps will default to it). And analyze.