I am working on a C# project that is using Azure DevOps for CI. I have a power shell file that is being run when the project is pushed to Azure. The relevant part of the build file is:
# $buildTools is the path to MSBuild.exe
# $solution is the path to the project's .sln file
& $buildTools $solution /t:Clean,Build /p:Configuration=Release,Platform=x86
if ($LASTEXITCODE -eq 0) {
Write-Host 'Build completed successfully!'
} else {
Write-Host '##vso[task.logissue type=error;]There were errors during the build of the application'
}
Currently, $LASTEXITCODE can either be 0 (no errors) or 1 (error). If the exit code is 0 everything is okay and Azure shows the green, passing badge; if it is 1 Azure shows the red, error badge. However, when there are warnings in the build they are shown in the logs and Azure shows the green badge.
My goal is to make Azure display a yellow/orange warning badge when there are warnings. Is this possible and how? Thank you very much for your time!
In the C# project properties the Warning level is set to 4; so I tried this modification to the power shell script, however, it did not work out.
& $buildTools $solution 4> 'warning.txt'
Thanks to D.J.'s answer! The final build line looks like:
# $warningsFile is a path to a file that will contain all the warnings
& $buildTools $solution /t:Clean,Build /p:Configuration=Release,Platform=x86 /fl1 "/flp1:$warningsFile;warningsonly"
You could use this -> https://learn.microsoft.com/en-us/visualstudio/msbuild/obtaining-build-logs-with-msbuild?view=vs-2017#save-the-log-output-to-multiple-files and write all warnings into a logfile, then check if the log file contains anything and then write the warnings to the output using theese commands (https://github.com/Microsoft/azure-pipelines-tasks/blob/master/docs/authoring/commands.md)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With