2

I want to fail the Jenkins build if during of execution "dotnet build", there will be compiler warning. I try to use "Record the compiler warning..." in "Post-build step". We have .editorconfig file for code style of our project. So if we will have warnings that noted in this file, my Jenkins build must be failed.

  • https://stackoverflow.com/questions/15552055/msbuild-treat-single-warning-as-error So run `dotnet build /p:TreatWarningsAsErrors=true`. – Lex Li Jan 20 '20 at 20:48

2 Answers2

0

your question has little to do with Jenkins. If a script returns an error exit code, jenkins will fail.

To do that you could specify some option on your executable. It looks like /WarnAsError should do the trick. however I see on github that that might not work https://github.com/dotnet/core-sdk/issues/1708

Or you could execute an external program like this one for instance https://github.com/editorconfig-checker/editorconfig-checker/ I haven't tried it but it looks that it could do the job ;)

fredericrous
  • 2,833
  • 1
  • 25
  • 26
0

As an "ultimate" solution, you could use log parser plugin: https://wiki.jenkins.io/display/JENKINS/Log+Parser+Plugin. It has functionality to fail a job based on messages in console log.

Another thing you probably should think about is how you run 'dotnet build' command. Jenkins taking into the account the latest exit code of the whole script. So if you run something like

dotnet build ...;
rm -R ...;

Jenkins uses exit code of rmdir command.