{"id":802,"date":"2014-05-19T12:35:51","date_gmt":"2014-05-19T12:35:51","guid":{"rendered":"https:\/\/www.happiestminds.com\/blogs\/?p=802"},"modified":"2024-04-11T08:41:12","modified_gmt":"2024-04-11T08:41:12","slug":"how-to-set-up-sonar-on-jenkins-for-net-projects","status":"publish","type":"post","link":"https:\/\/www.happiestminds.com\/blogs\/how-to-set-up-sonar-on-jenkins-for-net-projects\/","title":{"rendered":"How to Set up Sonar on Jenkins for .net Projects"},"content":{"rendered":"<div id=\"bsf_rt_marker\"><\/div><p style=\"text-align: left;\">Historically, .Net projects have used technologies from within Microsoft stack to achieve their goals and objectives. With the strong emergence of excellent Open Source tools and the phenomenal growth of OpenStack, the trend is changing. Projects that use Microsoft Technologies are now seen building affinity towards open source tools for continuous integration, development and improvement. However, not many sites\/tutorials are available, that helps a project in Microsoft Technology stack to leverage open source tools.<\/p>\n<p style=\"text-align: left;\">SonarQube is an open platform to manage code quality. This article guides a user on how to setup SonarQube in Jenkins server and simplify the adoption of the tool.<\/p>\n<h2>Installation of Sonarqube<\/h2>\n<p style=\"text-align: left;\">1. Download SonarQube from <a style=\"color: blue;\" href=\"http:\/\/www.sonarqube.org\/downloads\/\" target=\"_blank\" rel=\"noopener\"> http:\/\/www.sonarqube.org\/downloads\/<\/a><br \/>\n2. Unzip the SonarQube distribution C:\\sonarqube<br \/>\n3. Start the SonarQube server:<br \/>\nC:\\sonarqube\\bin\\windows-x86-xx\\StartSonar.bat<br \/>\n4. Download SonarQube Runner from <a style=\"color: blue;\" href=\"http:\/\/www.sonarqube.org\/downloads\/\" target=\"_blank\" rel=\"noopener\"> http:\/\/www.sonarqube.org\/downloads\/<\/a><br \/>\n5. Unzip the SonarQube Runner<br \/>\nC:\\sonar-runner<br \/>\n6. Download examples<br \/>\n7. Unzip some project samples C:\\sonar-examples<br \/>\n8. Analyze Project<br \/>\ncd C:\\sonar-examples\\projects\\languages\\java\\sonar-runner\\java-sonar-runner-simple<br \/>\nC:\\sonar-runner\\bin\\sonar-runner.bat<br \/>\n9. Browse results at http:\/\/localhost:9000<br \/>\n10. Default system administrator credentials are admin\/admin<\/p>\n<h2>Install .Net Plugins for Sonar:<\/h2>\n<p style=\"text-align: left;\">1. Download c# Ecosystem plugin<br \/>\n2. Extract and copy the plugins to C:\\sonarqube\\extensions\\plugins<br \/>\n3. Start SonarQube<br \/>\n4. Verify that you are able to browse http:\/\/ localhost:9000 and login<br \/>\n5. Login to the SonarQube website as an Admin user and<br \/>\n6. Click the \u201cSettings\u201d link in the upper right-hand corner,<br \/>\n7. Go to Configuration<br \/>\n8. Set the appropriate path for Galileo, FxCop, StyleCop and any other plugin that you want to invoke.<br \/>\n9. Install Win7 SDK if you are analyzing projects .net framework 2.0 \/4.0; if the target framework is 4.5, install Win 8 SDK.<br \/>\n10. Download command-line tool from Resharper at:<a style=\"color: blue;\" href=\"http:\/\/www.jetbrains.com\/resharper\/features\/command-line.html\" target=\"_blank\" rel=\"noopener\"> http:\/\/www.jetbrains.com\/resharper\/features\/command-line.html<\/a><br \/>\n11. Unzip it to a folder C:\\jetbrains-commandline-tools<br \/>\n12. Go to update center -&gt; Available plugins<br \/>\n13. Choose .Net Resharper<br \/>\n14. Restart the SonarQube server<br \/>\n15. Login to SonarQube using admin-admin<\/p>\n<h2>Modify Your Project\u2019s Quality Profile<\/h2>\n<p style=\"text-align: left;\">1. Activate all 650 Resharper rules<br \/>\nGo to Quality Profiles -&gt; C# -&gt; Sonar way<br \/>\n2. Run Sonar runner from solution file to ensure Sonar is working correctly.<\/p>\n<h2>Modify the port where Sonar is running<\/h2>\n<p style=\"text-align: left;\">1. Change the sonar-properties files to have the port as 9010<br \/>\nsonar.web.host: 0.0.0.0<br \/>\nsonar.web.port: 9010<br \/>\nsonar.web.context: \/<\/p>\n<p>2. Change the wrapper.conf and add following line<br \/>\nwrapper.java.additional.3=-Djava.io.tmpdir=..\/..\/temp\/<\/p>\n<p>3. Run Sonar as a Windows Service<br \/>\n%SONARQUBE_HOME%\/bin\/windows-x86-32\/InstallNTService.bat<\/p>\n<p>4. Start Sonar service<br \/>\n%SONARQUBE_HOME%\/bin\/windows-x86-32\/StartNTService.bat<\/p>\n<p>5. Change the Sonar runner properties file<br \/>\nsonar.host.url=http:\/\/localhost:9010<\/p>\n<h2>Install SonarQube Plugin on Jenkins<\/h2>\n<p style=\"text-align: left;\">1. Go to \u2018Jenkins\u2019 \u2013 \u2018Manage Plugins\u2019<br \/>\n2. Go to \u2018Available tab\u2019<br \/>\n3. Select \u2018Sonar plugin\u2019<br \/>\n4. Choose \u2018install without restart\u2019<br \/>\n5. Go to &#8216;Manage Jenkins\u2019 and verify if \u2018Sonar\u2019 is listed in the installed plugin list.<br \/>\n6. You can verify your installed list.<br \/>\n7. Now go to <a style=\"color: blue;\" target=\"_blank\" rel=\"noopener\">http:\/\/jenkins IP\/manage<\/a> page<br \/>\n8. Go to \u2018Configure System\u2019:<br \/>\n9. Go to \u2018Sonar configuration section\u2019 and click on \u2018Add Sonar:\u2019<br \/>\n10. Go to \u2018Configure sonar-runner\u2019<br \/>\n11. Go to the \u2018Build section\u2019, click on \u2018Add build step\u2019 and choose \u2018Invoke Standalone Sonar Analysis\u2019: <a style=\"color: blue;\" target=\"_blank\" rel=\"noopener\">http:\/\/&lt;IP&gt;:&lt;port&gt;\/job\/&lt;jobName&gt;\/configure<\/a><br \/>\n12. Add Invoke Standalone Sonar analysis<br \/>\n13. Configure the SonarQube analysis. You can either point to an existing sonar-project.properties-<sup style=\"vertical-align: super;\">1<\/sup> file or set the analysis properties directly in the Project properties field:<\/p>\n<p><strong>Note : Following is a sample Sonar Properties file:<\/strong><\/p>\n<p><strong># Project identification<\/strong><br \/>\nsonar.projectKey=HM:Sonar.TestApplication<br \/>\nsonar.projectVersion=1.0<br \/>\nsonar.projectName= Sonar.TestApplication<\/p>\n<h2># C# Specific Properties<\/h2>\n<p>sonar.sources=.<br \/>\nsonar.language=cs<br \/>\nsonar.dotnet.key.generation.strategy=safe<br \/>\nsonar.sourceEncoding=UTF-8<br \/>\nsonar.dotnet.assemblies=\/trunk\/dotnet\/vstudio\/Sonar.TestApplication.Projects\/Sonar.TestApplication.Data \\bin\\Debug\\$(AssemblyName)\\$(OutputType)<\/p>\n<h2># Plugin Specific Properties<\/h2>\n<p>sonar.resharper.mode=reuseReport<br \/>\nsonar.resharper.report.path=resharper-results.xml<br \/>\nsonar.resharper.mode=<br \/>\nsonar.resharper.installDirectory=c:\/jetbrains-commandline-tools<\/p>\n<p># Gallio \/ Unit Tests<br \/>\nsonar.gallio.mode=<br \/>\nsonar.gallio.coverage.tool=OpenCover<br \/>\nsonar.gallio.runner=Local<br \/>\nsonar.dotnet.visualstudio.testProjectPattern=*UnitTest*;Testing*<br \/>\nsonar.opencover.installDirectory=C:\/Program Files (x86)\/OpenCover\/<\/p>\n<p># FXCop<br \/>\nsonar.fxcop.mode=<\/p>\n<p># StyleCop<br \/>\nsonar.stylecop.mode=<\/p>\n<p>14. Now the Sonar is setup<br \/>\n15. You can trigger Sonar either from Jenkins or from command prompt.<\/p>\n<p style=\"text-align: left;\">\n<hr \/>\n<p style=\"font-size: 11px;\"><sup style=\"vertical-align: super;\">1<\/sup><em>Sonar project properties: A Sonar project file is the metadata that helps the sonar-runner to identify projects in the solution and run analysis against the solution. The Sonar runner file should be placed in the same folder that contains the c# solution. <sup>The Sonar<\/sup> runner file has three sections:<br \/>\n<span style=\"margin-left: 23px;\"> a. Project Properties<\/span><br \/>\n<span style=\"margin-left: 23px;\"> b. C# Specific Properties<\/span><br \/>\n<span style=\"margin-left: 23px;\"> c. Plugin Specific Properties<\/span><\/em><\/p>\n<div class=\"pld-like-dislike-wrap pld-template-2\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"Like\" data-post-id=\"802\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-heart\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">0    <\/span>\r\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Historically, .Net projects have used technologies from within Microsoft stack to achieve their goals and objectives. With the strong emergence of excellent Open Source tools and the phenomenal growth of OpenStack, the trend is changing. Projects that use Microsoft Technologies are now seen building affinity towards open source tools for continuous integration, development and improvement. [&hellip;]<\/p>\n","protected":false},"author":90,"featured_media":986,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[123],"tags":[293,294,295,296,297,298,299,300,301,302],"class_list":["post-802","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","tag-how-to-setup-jenkins","tag-jenkins-c","tag-jenkins-change-language","tag-jenkins-property-management","tag-jenkins-sonar","tag-project-sonar","tag-sonar-jenkins","tag-sonar-jenkins-plugin","tag-sonar-properties","tag-sonar-runner"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/posts\/802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/users\/90"}],"replies":[{"embeddable":true,"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/comments?post=802"}],"version-history":[{"count":1,"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/posts\/802\/revisions"}],"predecessor-version":[{"id":12368,"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/posts\/802\/revisions\/12368"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/media\/986"}],"wp:attachment":[{"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/media?parent=802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/categories?post=802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/tags?post=802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}