Created
May 7, 2025 13:50
-
-
Save JeffBrownTech/9fd2f5f1d949643f0cd16895ca1ccd71 to your computer and use it in GitHub Desktop.
Example Azure DevOps YAML Pipeline for PowerShell Build Validation
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
pr: | |
branches: | |
include: | |
- main | |
trigger: none | |
pool: | |
vmImage: ubuntu-latest | |
stages: | |
- stage: test | |
displayName: 'Test Code' | |
jobs: | |
- job: AnalyzeScripts | |
displayName: 'Analyze PowerShell Scripts' | |
steps: | |
- task: PowerShell@2 | |
displayName: 'Run Script Analyzer' | |
inputs: | |
targetType: inline | |
script: | | |
$files = Get-ChildItem -Path "$(Build.SourcesDirectory)" -Recurse -Filter "run.ps1" | |
if ($files.Count -eq 0) { | |
Write-Host "No run.ps1 files found. Skipping analysis." | |
exit 0 | |
} | |
foreach ($file in $files) { | |
Write-Host "Analyzing $($file.FullName)" | |
Invoke-ScriptAnalyzer -Path $file.FullName -Recurse -Severity Warning,Error -OutVariable results | |
if ($results) { | |
Write-Error "ScriptAnalyzer found issues in $($file.FullName)" | |
exit 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment