Skip to content

Commit

Permalink
Adding Steps for PSScriptAnalyzer and Installing PSDevOps.
Browse files Browse the repository at this point in the history
Adding PowerShell Static Analysis Stage
  • Loading branch information
StartAutomating committed Nov 20, 2019
1 parent 8a5dd57 commit 14c113f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Ado/Stages/PowerShellStaticAnalysis.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@{
stage = 'PowerShellStaticAnalysis'
displayName = 'Static Analysis'
condition= "and(succeeded())"
jobs = @(@{
job = 'PSScriptAnalyzer'
displayName = 'PSScriptAnalyzer'
pool=@{
vmImage= 'vs2017-win2016'
}
steps = @('InstallPSDevOps', 'InstallPSScriptAnalyzer','RunPSScriptAnalyzer')
})
}
2 changes: 2 additions & 0 deletions Ado/Steps/InstallPSDevOps.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Install-Module -Name PSDevOps -Repository PSGallery -Force -Scope CurrentUser
Import-Module PSDevOps -Force -PassThru
2 changes: 2 additions & 0 deletions Ado/Steps/InstallPSScriptAnalyzer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Install-Module -Name PSScriptAnalyzer -Repository PSGallery -Force -Scope CurrentUser
Import-Module PSScriptAnalyzer -Force -PassThru
15 changes: 15 additions & 0 deletions Ado/Steps/RunPSScriptAnalyzer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Import-Module PSScriptAnalyzer, PSDevOps
$invokeScriptAnalyzerSplat = @{Path='.\'}
if ($ENV:PSScriptAnalyzer_Recurse) {
$invokeScriptAnalyzerSplat.Recurse = $true
}
$result = Invoke-ScriptAnalyzer @invokeScriptAnalyzerSplat

foreach ($r in $result) {
if ('information', 'warning' -contains $r.Severity) {
Write-ADOWarning -Message $r.Message -SourcePath $r.ScriptPath -LineNumber $r.LineNumber -ColumnNumber $r.ColumnNumber
}
elseif ($r.Severity -eq 'Error') {
Write-ADOError -Message $r.Message -SourcePath $r.ScriptPath -LineNumber $r.LineNumber -ColumnNumber $r.ColumnNumber
}
}

0 comments on commit 14c113f

Please sign in to comment.