From 1f63817433c2c6b119885bd6cc499317b316c37f Mon Sep 17 00:00:00 2001 From: "Christoph Bergmeister [MVP]" Date: Mon, 15 Jun 2020 17:00:09 +0100 Subject: [PATCH] CI: Report full stack trace if ScriptAnalyzer throws an error and improve ScriptAnalyzer installation to not skip publisher and check and not allow clobber (#236) #221 reported that this repo causes PSScriptAnalyzer to sporadically throw an error. In order to report the full error needed for analysis, report the full stack trace. In order to make this easier, I've updated `Invoke-ScriptAnalyzer` to run within a `try/catch using -ErrorAction Stop`, and report any error found with `$_.Exception.StackTrace` before re-throwing the error. --- CONTRIBUTING.md | 1 + build/pipelines/templates/run-staticAnalysis.yaml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dff45883..3bb7e8d8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -486,6 +486,7 @@ Thank you to all of our contributors, no matter how big or small the contributio - **[Shannon Deminick (@Shazwazza)](http://github.com/Shazwazza)** - **[Jess Pomfret (@jpomfret)](https://github.com/jpomfret)** - **[Giuseppe Campanelli (@themilanfan)](https://github.com/themilanfan)** +- **[Christoph Bergmeister (@bergmeister)](https://github.com/bergmeister)** ---------- diff --git a/build/pipelines/templates/run-staticAnalysis.yaml b/build/pipelines/templates/run-staticAnalysis.yaml index feddaa9b..86a673fc 100644 --- a/build/pipelines/templates/run-staticAnalysis.yaml +++ b/build/pipelines/templates/run-staticAnalysis.yaml @@ -5,11 +5,11 @@ steps: - powershell: | - Install-Module -Name PSScriptAnalyzer -Repository PSGallery -Scope CurrentUser -AllowClobber -SkipPublisherCheck -Force -Verbose + Install-Module -Name PSScriptAnalyzer -Repository PSGallery -Scope CurrentUser -Force -Verbose displayName: 'Install PSScriptAnalyzer' - powershell: | - $results = Invoke-ScriptAnalyzer -Path ./ –Recurse + $results = try { Invoke-ScriptAnalyzer -Path ./ –Recurse -ErrorAction Stop } catch { $_.Exception.StackTrace; throw } $results | ForEach-Object { Write-Host "##vso[task.logissue type=$($_.Severity);sourcepath=$($_.ScriptPath);linenumber=$($_.Line);columnnumber=$($_.Column);]$($_.Message)" } $null = New-Item -Path ..\ -Name ScriptAnalyzer -ItemType Directory -Force