From 8a7f23bba0f04524297ed789220bfb8f14977331 Mon Sep 17 00:00:00 2001 From: ryfu-msft Date: Tue, 27 Aug 2024 10:46:01 -0700 Subject: [PATCH 1/2] add psscript analyzer to build pipeline --- pipelines/azure-pipelines.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pipelines/azure-pipelines.yml b/pipelines/azure-pipelines.yml index e370b59a..7fbbdc21 100644 --- a/pipelines/azure-pipelines.yml +++ b/pipelines/azure-pipelines.yml @@ -93,4 +93,21 @@ extends: inputs: testResultsFormat: "NUnit" testResultsFiles: "**/Test*.xml" - failTaskOnFailedTests: true \ No newline at end of file + failTaskOnFailedTests: true + + - task: PowerShell@2 + displayName: "Run PSScriptAnalyzer for DSC modules" + inputs: + pwsh: true + targetType: "inline" + script: | + Invoke-ScriptAnalyzer -Path *.ps1 -Recurse -Outvariable issues + $errors = $issues.Where({$_.Severity -eq 'Error'}) + $warnings = $issues.Where({$_.Severity -eq 'Warning'}) + if ($errors) + { + Write-Error "There were $($errors.Count) errors." -ErrorAction Stop + } + Write-Output "There were $($warnings.Count) warnings total." + workingDirectory: $(Build.SourcesDirectory)\resources\ + ignoreLASTEXITCODE: true \ No newline at end of file From 52dd436bc4b5d25cdf8553008c279b247d3c1f46 Mon Sep 17 00:00:00 2001 From: ryfu-msft Date: Tue, 27 Aug 2024 10:50:36 -0700 Subject: [PATCH 2/2] fix path --- pipelines/azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/azure-pipelines.yml b/pipelines/azure-pipelines.yml index 7fbbdc21..74b1f084 100644 --- a/pipelines/azure-pipelines.yml +++ b/pipelines/azure-pipelines.yml @@ -101,7 +101,7 @@ extends: pwsh: true targetType: "inline" script: | - Invoke-ScriptAnalyzer -Path *.ps1 -Recurse -Outvariable issues + Invoke-ScriptAnalyzer -Path * -Recurse -Outvariable issues $errors = $issues.Where({$_.Severity -eq 'Error'}) $warnings = $issues.Where({$_.Severity -eq 'Warning'}) if ($errors)