Skip to content

Commit

Permalink
CI: Report full stack trace if ScriptAnalyzer throws an error and imp…
Browse files Browse the repository at this point in the history
…rove 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.
  • Loading branch information
bergmeister authored Jun 15, 2020
1 parent 08ff284 commit 1f63817
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)**

----------

Expand Down
4 changes: 2 additions & 2 deletions build/pipelines/templates/run-staticAnalysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1f63817

Please sign in to comment.