Created
November 22, 2013 19:04
-
-
Save k0stya/7605121 to your computer and use it in GitHub Desktop.
Warning report for TeamCity
http://homenko.net/post/2013/11/22/Enhanced-MSBuild-Warning-report-in-TeamCity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param( | |
[parameter(Mandatory=$true)] | |
[alias("f")] | |
$FilePath, | |
[alias("b")] | |
$BuildTypeId, | |
[alias("s")] | |
$ServerUrl, | |
[parameter()] | |
[alias("o")] | |
$RawOutputPath | |
) | |
$warnings = @(Get-Content -ErrorAction Stop $FilePath | # Get the file content | |
Where {$_ -match '^.*warning CS.*$'} | # Extract lines that match warnings | |
%{ $_.trim() -replace "^\s*\d+>","" } | # Strip out any project number and caret prefixes | |
sort-object | Get-Unique -asString) # remove duplicates by sorting and filtering for unique strings | |
$count = $warnings.Count | |
# raw output | |
Write-Host "MSBuild Warnings - $count warnings ===================================================" | |
$warnings | % { Write-Host " * $_" } | |
try{ | |
$previousWarnings = ((new-object Net.WebClient).DownloadString("$ServerUrl/repository/download/$BuildTypeId/.lastSuccessful/$RawOutputPath" + "?guest=1").Trim()) -split "`r`n" | |
}catch{ | |
$previousWarnings = @() | |
Write-Host $Error | |
} | |
$wcount = 0 | |
$new = @() | |
$old = @() | |
while($warnings.Length -ne $wcount){ | |
if($previousWarnings -notcontains $warnings[$wcount]) | |
{ | |
$new+=$warnings[$wcount] | |
} else{ | |
$old+=$warnings[$wcount] | |
} | |
$wcount += 1 | |
} | |
#TeamCity output | |
Write-Host ("##teamcity[buildStatus text='{build.status.text}, Build warnings: $count (+" + $new.Length + "/-" + ($previousWarnings.Length - $old.Length) + ")']") | |
Write-Host "##teamcity[buildStatisticValue key='buildWarnings' value='$count']" | |
Write-Host $RawOutputPath | |
# file output | |
if($RawOutputPath){ | |
Write-Host "Writing to row file" | |
$stream = [System.IO.StreamWriter] $RawOutputPath | |
$warnings | % { $stream.WriteLine("$_") } | |
$stream.Close() | |
} | |
# html report output | |
$check = Test-Path -PathType Container BuildWarningReport | |
if($check -eq $false){ | |
New-Item 'BuildWarningReport' -type Directory | |
} | |
$stream = [System.IO.StreamWriter] "BuildWarningReport/index.html" | |
$stream.WriteLine("<html><head></head><body><h1>$count Build Warnings</h1>") | |
if($new.Length -gt 0){ | |
$stream.WriteLine("New warnings:<ul>") | |
$new | % { $stream.WriteLine("<li style='color:red'>$_</li>") } | |
$stream.WriteLine("</ul>") | |
} | |
if($old.Length -gt 0){ | |
$stream.WriteLine("Old warnings:<ul>") | |
$stream.WriteLine("<ul>") | |
$old | % { $stream.WriteLine("<li>$_</li>") } | |
$stream.WriteLine("</ul>") | |
} | |
$stream.WriteLine("</body></html>") | |
$stream.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment