PowerShell Error Handling — Resilient Deployment Scripts
Write production-grade PowerShell scripts that handle failures gracefully:
```powershell
$ErrorActionPreference = 'Stop'
function Deploy-Production {
try {
Write-Host "Running tests..." -ForegroundColor Cyan
npm test
Write-Host "Building app..." -ForegroundColor Cyan
npm run build
Write-Host "Deploying to Firebase..." -ForegroundColor Green
npx firebase deploy --only hosting
Write-Host "✅ Deployment successful!" -ForegroundColor Green
}
catch {
Write-Host "❌ Deployment failed: $_" -ForegroundColor Red
Write-Host "Rolling back..." -ForegroundColor Yellow
# Rollback logic here
exit 1
}
finally {
Write-Host "Deployment pipeline complete."
}
}
Deploy-Production
`
This is how real production deployment scripts handle failures! 🛡️
