Skip to content

Instantly share code, notes, and snippets.

@deekayen
Created August 8, 2017 18:54
Show Gist options
  • Save deekayen/127b895a1d9220250f5c349b18d7867d to your computer and use it in GitHub Desktop.
Save deekayen/127b895a1d9220250f5c349b18d7867d to your computer and use it in GitHub Desktop.
Scan a workspace of Java code using Visual Code Grepper and save the result as a CSV file to a Windows network share. Filter for high and critical findings only.
$file = "\\localhost\d$\Reports\Releases\$env:JOB_NAME\$env:BUILD_ID\tfsvcgscan.csv"
cd "C:\Program Files (x86)\VisualCodeGrepper"
Write-Host "Creating destination directory..."
New-Item -Force -ItemType Directory -path "\\localhost\d$\Reports\Releases\$env:JOB_NAME\$env:BUILD_ID"
Write-Host "Writing to \\localhost\d$\Reports\Releases\$env:JOB_NAME\$env:BUILD_ID\tfsvcgscan.csv"
Write-Host "Running VisualCodeGrepper.exe..."
& .\VisualCodeGrepper.exe --verbose --console --target "$env:WORKSPACE" --language JAVA --csv-export "$file" | Write-Verbose
# Look for High or Critical findings.
# Help mark build unstable if found.
Write-Host "Looking for High and Critical findings..."
if (Test-Path "$file") {
if ((Get-Content "$file") -match 'High|Critical') {
Write-Host "Warning: High or Critical findings found! UNSTABLE"
}
} else {
Write-Host "No results file to grep."
}
Write-Host "Filtering CSV output to just important findings..."
$csv = Get-Content $file
$csv | Select-String -pattern 'High|Critical' | Out-File $file -width 32767
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment