Show build issues (warnings / errors) in Azure Devops for .NET Core projects. Solution for the issue mentioned here: microsoft/azure-pipelines-tasks#7749
When building .NET core projects in the Azure Devops pipeline with the dotnetcli, the build warnings are not shown in the Build Log / Build Summary views.
Write the dotnet build
output to a log file and convert all the issues to a VSO issue.
This is done in the azure-pipelines.yml
in this repo. You are free to copy this to your own repo!
-
Add the
.NET Core
restore task to your build pipeline -
Add the
.NET Core
build task to your bulid pipeline and update the arguments to:--configuration $(BuildConfiguration) --no-incremental /flp:v=q /flp:logfile=MyLog.log
-
Add the
Powershell
task to your build after the.NET Core - build
task. Set theType
toInline
. Copy paste this script to theScript
field:$output = Get-Content -Path "$(System.DefaultWorkingDirectory)/MyLog.log"; $warnings = $output | Select-String -Pattern ".*:\s"; $hasErrors = $false; [regex]$issueTypeRegex = "(warning|error)"; [regex]$issueLocationRegex = "(\d+,\d+)"; [regex]$sourcePathRegex = "^[^/(]*"; [regex]$issueCodeRegex = "(?<=(warning|error) )[A-Za-z0-9]+"; [regex]$messageRegex = "(?<=((warning|error) [A-Za-z0-9]+: )).*"; $warnings | Foreach-Object { $issueLocationMatch = $issueLocationRegex.Matches($_)[0]; if ($issueLocationMatch) { $issueLocation = $issueLocationMatch.value.split(","); } else { $issueLocation = "unknown"; } $issueLocation = $issueLocationMatch.value.split(","); $issueType = $issueTypeRegex.Matches($_)[0]; $sourcepath = $sourcePathRegex.Matches($_)[0]; $linenumber = $issueLocation[0]; $columnnumber = $issueLocation[1]; $issueCode = $issueCodeRegex.Matches($_)[0]; $message = $messageRegex.Matches($_)[0]; Write-Host "##vso[task.logissue type=$issueType;sourcepath=$sourcepath;linenumber=$linenumber;columnnumber=$columnnumber;code=$issueCode;]$message"; if($issueType.Value -eq "error") { $hasErrors = $true; } }; if($warnings.Count -gt 0 -and $hasErrors -eq $true) { Write-Host "##vso[task.complete result=Failed;]There are build errors"; } elseif($warnings.Count -gt 0 -and $hasErrors -eq $false) { Write-Host "##vso[task.complete result=SucceededWithIssues;]There are build warnings"; }
Update the
Control Options: Run this task
toEven if a previous task has failed, unless the build was cancelled
to make sure that this script will run after a failing build which might be caused by CA errors.
Logs tab when only having warnings: