From 14c113f2b102e9fd78d11c3da71d7b12f79bb9fc Mon Sep 17 00:00:00 2001 From: StartAutomating Date: Tue, 19 Nov 2019 19:19:58 -0800 Subject: [PATCH] Adding Steps for PSScriptAnalyzer and Installing PSDevOps. Adding PowerShell Static Analysis Stage --- Ado/Stages/PowerShellStaticAnalysis.psd1 | 13 +++++++++++++ Ado/Steps/InstallPSDevOps.ps1 | 2 ++ Ado/Steps/InstallPSScriptAnalyzer.ps1 | 2 ++ Ado/Steps/RunPSScriptAnalyzer.ps1 | 15 +++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 Ado/Stages/PowerShellStaticAnalysis.psd1 create mode 100644 Ado/Steps/InstallPSDevOps.ps1 create mode 100644 Ado/Steps/InstallPSScriptAnalyzer.ps1 create mode 100644 Ado/Steps/RunPSScriptAnalyzer.ps1 diff --git a/Ado/Stages/PowerShellStaticAnalysis.psd1 b/Ado/Stages/PowerShellStaticAnalysis.psd1 new file mode 100644 index 00000000..e7f8c7ab --- /dev/null +++ b/Ado/Stages/PowerShellStaticAnalysis.psd1 @@ -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') + }) +} diff --git a/Ado/Steps/InstallPSDevOps.ps1 b/Ado/Steps/InstallPSDevOps.ps1 new file mode 100644 index 00000000..15e0e847 --- /dev/null +++ b/Ado/Steps/InstallPSDevOps.ps1 @@ -0,0 +1,2 @@ +Install-Module -Name PSDevOps -Repository PSGallery -Force -Scope CurrentUser +Import-Module PSDevOps -Force -PassThru \ No newline at end of file diff --git a/Ado/Steps/InstallPSScriptAnalyzer.ps1 b/Ado/Steps/InstallPSScriptAnalyzer.ps1 new file mode 100644 index 00000000..713692a1 --- /dev/null +++ b/Ado/Steps/InstallPSScriptAnalyzer.ps1 @@ -0,0 +1,2 @@ +Install-Module -Name PSScriptAnalyzer -Repository PSGallery -Force -Scope CurrentUser +Import-Module PSScriptAnalyzer -Force -PassThru \ No newline at end of file diff --git a/Ado/Steps/RunPSScriptAnalyzer.ps1 b/Ado/Steps/RunPSScriptAnalyzer.ps1 new file mode 100644 index 00000000..28ea70d0 --- /dev/null +++ b/Ado/Steps/RunPSScriptAnalyzer.ps1 @@ -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 + } +} \ No newline at end of file