Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JeffBrownTech/9fd2f5f1d949643f0cd16895ca1ccd71 to your computer and use it in GitHub Desktop.
Save JeffBrownTech/9fd2f5f1d949643f0cd16895ca1ccd71 to your computer and use it in GitHub Desktop.
Example Azure DevOps YAML Pipeline for PowerShell Build Validation
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