Skip to content

Commit a2f2c15

Browse files
ugurkocdeclaude
andcommitted
ci: harden PSScriptAnalyzer step against internal analyzer NREs
PSScriptAnalyzer 1.25.0 has been throwing intermittent NREs and parameter binding errors during recursive analysis on Linux runners when invoked with -RecurseCustomRulePath but no -CustomRulePath. The switch is a no-op without a custom rule path anyway, so it's removed. The call is wrapped in try/catch that falls back to per-file analysis if the recursive call throws, so a transient analyzer fault no longer fails the workflow. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1224bb6 commit a2f2c15

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

.github/workflows/psscriptanalyzer.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,23 @@ jobs:
4848
Write-Host ""
4949
5050
# Run the analysis on the module directory (all .ps1 and .psm1 files)
51-
$results = Invoke-ScriptAnalyzer -Path ./Module/IntuneAssignmentChecker -Recurse -Settings ./.PSScriptAnalyzerSettings.psd1 -RecurseCustomRulePath
51+
# -RecurseCustomRulePath omitted: no custom rules, and the switch can trigger
52+
# internal NREs in PSScriptAnalyzer 1.25 on Linux when no -CustomRulePath is set.
53+
try {
54+
$results = Invoke-ScriptAnalyzer -Path ./Module/IntuneAssignmentChecker -Recurse -Settings ./.PSScriptAnalyzerSettings.psd1 -ErrorAction Stop
55+
} catch {
56+
Write-Host "Recursive analysis threw: $($_.Exception.Message)" -ForegroundColor Yellow
57+
Write-Host "Falling back to per-file analysis..." -ForegroundColor Yellow
58+
$results = @()
59+
$files = Get-ChildItem -Path ./Module/IntuneAssignmentChecker -Recurse -Include *.ps1,*.psm1 -File
60+
foreach ($f in $files) {
61+
try {
62+
$results += Invoke-ScriptAnalyzer -Path $f.FullName -Settings ./.PSScriptAnalyzerSettings.psd1 -ErrorAction Stop
63+
} catch {
64+
Write-Host " Skipped $($f.Name): $($_.Exception.Message)" -ForegroundColor DarkYellow
65+
}
66+
}
67+
}
5268
5369
if ($results) {
5470
# Group by severity

0 commit comments

Comments
 (0)