Fail build in Visual Studio if any error level sonarlint rule violates

1,678 views
Skip to first unread message

nikhil...@gmail.com

unread,
Nov 25, 2016, 6:26:36 AM11/25/16
to SonarLint
Hi,

I am using SonarQube for code analysis for my C# .net project at server level and using SonarLint at development level.

I wanted to fail my build if any error level SonarLint rule violates.

Solutions which i have already tried:
1) Changed the Action of all rules to error.
2) Enabled code analysis on build on all configurations.
3) Changed "Treat warnings as errors" to "ALL".

But none of above worked for me. My build gets failed only if any Microsoft.Code.Analysis rules violates.

Please help because i wanted to make sure that all the compulsory rules should be fixed before developer check-in there code.

Thanks & Regards,
Nikhil Gupta



Tamas Vajk

unread,
Nov 29, 2016, 5:58:13 AM11/29/16
to nikhil...@gmail.com, SonarLint
Hello Nikhil,

We think that breaking the build in VS is not a good idea, therefore we override the "treat warnings as errors" setting. Also, SQ severities are therefore also mapped to at max warning.
So at the moment I think there's no way you can achieve this.

However I think this comes down to a more fundamental question. Why do you want to do this?
What you say here "I wanted to make sure that all the compulsory rules should be fixed before developer check-in there code." is a valid requirement. And we also have this internally at SonarSource. We're developing everything in Git branches, and use pull requests. And each of our PRs are analyzed by SonarQube. Isn't this what you actually want: http://www.sonarqube.org/github-pull-request-analysis-helps-fix-the-leak/

Regards,
Tamas

Tamas VAJK | SonarSource
Language Team

--
You received this message because you are subscribed to the Google Groups "SonarLint" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarlint/02d073e2-d7cc-4f12-8df0-e5a9b2fc0d9d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

pratik...@gmail.com

unread,
Dec 2, 2016, 2:27:52 AM12/2/16
to SonarLint, nikhil...@gmail.com
Hello Tamas,
I have a contradictory issue with what Nikhil is saying.

I integrated SonarLint v2.8.0.214 with VS2015. In my case, As per SonarQube server (v5.2.0.5 as C# plugin) there are 2195 (major) and 2457 (minor) errors. So when I bind SonarLint to my IDE it should show a total of 4652 (2195 + 2457) errors  / warnings.
However, at the time of building the solution,  the build fails at Project "A". When I exclude that project from analysis (Right click Project "A" -> SonarLint Connected Mode -> exclude from Analysis"), the entire solution is build, but with only 486 warnings.

I don't understand where I am going wrong.
Also I don't see much of the settings for SonarLint in Visual Studio.

My target is:
=> To bind the SonarLint to all my projects in VS2015
=> Perform analysis during build time and show me exact count of issues as seen on the SonarQube server
=> Show errors but don't fail the build.

Thanking you in advance.

Regards
Pratik Shah
To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+...@googlegroups.com.

Tamas Vajk

unread,
Dec 2, 2016, 2:32:10 AM12/2/16
to pratik...@gmail.com, SonarLint, Nikhil Gupta
Hello Pratik,

Could you share a minimal repro of this issue?
What is the project type of "Project A"?
What other plugins do you have on SonarQube?
Which analyzer DLLs are referenced in "Project A" under References/Analyzers?

Thank you,
Tamas

Tamas VAJK | SonarSource
Language Team

To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarlint/0c0e78d5-f33f-4e8f-9ec6-8331e185dd27%40googlegroups.com.

pratik...@gmail.com

unread,
Dec 2, 2016, 3:53:29 AM12/2/16
to SonarLint, pratik...@gmail.com, nikhil...@gmail.com
Ideally there is no repro as such. I have just binded the project
Project A is a normal C# project (Clas Library)
On Sonarqube there are no other plugins for .Net. We have C# plugin installed with the latest version.
There are 2 of them  (1) SonarAnalyzer (2)SonarAnalyzer.Csharp. This 2nd file contains the list of all the rules that we have created in SonarQube server.

Tamas Vajk

unread,
Dec 2, 2016, 4:11:06 AM12/2/16
to pratik...@gmail.com, SonarLint, Nikhil Gupta
Hello, 

Can you tell me the version of the installed SonarAnalyzer? Under References/Analyzers is there a Protobuf dll too?
BTW as far as I understand the analyzers are properly installed for every other project, is that right?
So what makes "Project A" special? Is it a test project? Does its name contain "test"? Did it already have a RuleSet file?

Thanks,
Tamas


Tamas VAJK | SonarSource
Language Team

To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarlint/8e09f89e-7b0e-4754-83dc-143a7526f3c6%40googlegroups.com.

pratik...@gmail.com

unread,
Dec 2, 2016, 4:25:37 AM12/2/16
to SonarLint, pratik...@gmail.com, nikhil...@gmail.com
=> Don't know abt the Sonar Analyzer, but the version of the SonarQubeRunner is 2.4
=> No there is nowhere a Protobuf dll
=> yes u are correct. Each and every project has a reference of analyser and a corresponding ruleset
=> No its not a test project, nor have a word "test". yes after binding it had a ruleset file with the name "A.ruleset"

pratik...@gmail.com

unread,
Dec 2, 2016, 5:52:48 AM12/2/16
to SonarLint
Any updates / alternatives?

Tamas Vajk

unread,
Dec 2, 2016, 6:27:18 AM12/2/16
to Pratik Shah, SonarLint
Hello, 

No idea yet. Without seeing your "Project A" it's only a guess work.

So let's come back to this: "However, at the time of building the solution,  the build fails at Project "A"."

What is the error that causes the build to fail?

Thanks,
Tamas

Tamas VAJK | SonarSource
Language Team

On 2 December 2016 at 11:52, <pratik...@gmail.com> wrote:
Any updates / alternatives?

--
You received this message because you are subscribed to the Google Groups "SonarLint" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarlint/89cd06dd-b30e-4839-9d5c-ec435ae38a09%40googlegroups.com.

pratik...@gmail.com

unread,
Dec 2, 2016, 7:28:24 AM12/2/16
to SonarLint
The errors are the same as i currently see in sonarqube server

pratik...@gmail.com

unread,
Dec 2, 2016, 7:36:55 AM12/2/16
to SonarLint
But my problem is why am i getting the errors? Initially i want to treat them as warnings, so tht my build can be successful. As and when i work on that module, i will treat those errors / warnings.

Tamas Vajk

unread,
Dec 2, 2016, 9:13:50 AM12/2/16
to Pratik Shah, SonarLint
Do you have the "treat warnings as errors" MsBuild property set on "Project A" and not on any of your other projects?

Tamas

Tamas VAJK | SonarSource
Language Team

On 2 December 2016 at 13:36, <pratik...@gmail.com> wrote:
But my problem is why am i getting the errors? Initially i want to treat them as warnings, so tht my build can be successful. As and when i work on that module, i will treat those errors / warnings.
--
You received this message because you are subscribed to the Google Groups "SonarLint" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+unsubscribe@googlegroups.com.

pratik...@gmail.com

unread,
Dec 2, 2016, 10:12:46 AM12/2/16
to SonarLint, pratik...@gmail.com
Thans Tamas,
It looks like that sorted out the issue. I need to set the value to "None" instead of "All" for each and every project which threw errors. By doing this, it moved all the issues of SonarQube as warning in Visual Studio during build time.

So does that mean that:
=> as and when I work on this affected module, I will keep on rectifying all the warnings and bringing them donw to 0? Till that time all the errors of those affected modules (new ones and the old ones) will be treated as "Warnings" and not "Errors"?
=> Once all the errors / warnings of that project are rectified and certified by SonarQube, I need to change the setting back to "All from?


On Friday, 2 December 2016 19:43:50 UTC+5:30, tamas.vajk wrote:
Do you have the "treat warnings as errors" MsBuild property set on "Project A" and not on any of your other projects?

Tamas

Tamas VAJK | SonarSource
Language Team

On 2 December 2016 at 13:36, <pratik...@gmail.com> wrote:
But my problem is why am i getting the errors? Initially i want to treat them as warnings, so tht my build can be successful. As and when i work on that module, i will treat those errors / warnings.

--
You received this message because you are subscribed to the Google Groups "SonarLint" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+...@googlegroups.com.

nikhil...@gmail.com

unread,
Dec 26, 2016, 3:58:20 AM12/26/16
to SonarLint, nikhil...@gmail.com
Hello Tamas,

Sorry it took me so long to reply on this, actually i was not well. Tamas, as you mentioned that what i wanted to achieve it is possible with GitHub pull request but in our organization for Source Control we are using TFS 2015, so is there any way i can achieve the same with TFS.

I also tried to bind SonarQube Analysis commands with my Visual Studio build events and it shows me all the SonarQube Error in my error console without Sonarlint but still my build is not failed whether all of my rules are fail.

Kindly help on this, all i wanted is to restrict a developer to check-in any code which violates mandatory Sonar rules.

Thanks & Regards,
Nikhil Gupta 
Merry Christmas!



On Tuesday, 29 November 2016 16:28:13 UTC+5:30, tamas.vajk wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages