From e95ec9218c3d81b83575a585c813f0129c21d678 Mon Sep 17 00:00:00 2001 From: Bernie White Date: Mon, 17 Oct 2022 22:15:30 +1000 Subject: [PATCH] Added outcome filtering #570 --- .azure-pipelines/azure-pipelines.yaml | 6 +++--- CHANGELOG.md | 3 +++ tasks/ps-rule-assertV2/powershell.ps1 | 9 +++++++++ tasks/ps-rule-assertV2/powershell.ts | 4 ++++ tasks/ps-rule-assertV2/task.json | 8 ++++++++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.azure-pipelines/azure-pipelines.yaml b/.azure-pipelines/azure-pipelines.yaml index 29b74549..fb24fbfe 100644 --- a/.azure-pipelines/azure-pipelines.yaml +++ b/.azure-pipelines/azure-pipelines.yaml @@ -2,12 +2,12 @@ # CI pipeline for PSRule-pipelines variables: - version: '2.4.0' + version: '2.5.0' buildConfiguration: 'Release' publish: 'true' imageName: 'ubuntu-20.04' -# Use build number format, i.e. 2.4.0-B2106001 +# Use build number format, i.e. 2.5.0-B2106001 name: $(version)-B$(date:yyMM)$(rev:rrr) trigger: @@ -146,7 +146,7 @@ stages: action: edit tag: '$(Build.SourceBranchName)' releaseNotesSource: inline - releaseNotesInline: 'See [change log](https://github.com/Microsoft/PSRule-pipelines/blob/main/CHANGELOG.md)' + releaseNotesInline: 'See [change log](https://github.com/microsoft/PSRule-pipelines/blob/main/CHANGELOG.md)' assetUploadMode: replace addChangeLog: false isPreRelease: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 62b42387..d61fd514 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ See [upgrade notes][1] for helpful information when upgrading from previous vers What's changed since v2.4.2: +- General improvements: + - Added outcome filtering parameter by @BernieWhite. + [#570](https://github.com/microsoft/PSRule-pipelines/issues/570) - Engineering: - Bump typescript to v4.8.4. [#546](https://github.com/microsoft/PSRule-pipelines/pull/546) diff --git a/tasks/ps-rule-assertV2/powershell.ps1 b/tasks/ps-rule-assertV2/powershell.ps1 index 47b0105f..94081ef9 100644 --- a/tasks/ps-rule-assertV2/powershell.ps1 +++ b/tasks/ps-rule-assertV2/powershell.ps1 @@ -42,6 +42,10 @@ param ( [Parameter(Mandatory = $False)] [String]$Option = (Get-VstsInput -Name 'option'), + # Filters output to include results with the specified outcome. + [Parameter(Mandatory = $False)] + [String]$Outcome = (Get-VstsInput -Name 'outcome'), + # The output format [Parameter(Mandatory = $False)] [ValidateSet('None', 'Yaml', 'Json', 'Markdown', 'NUnit3', 'Csv', 'Sarif')] @@ -268,6 +272,7 @@ Write-Host "[info] Using Conventions: $Conventions"; Write-Host "[info] Using InputType: $InputType"; Write-Host "[info] Using InputPath: $InputPath"; Write-Host "[info] Using Option: $Option"; +Write-Host "[info] Using Option: $Outcome"; Write-Host "[info] Using OutputFormat: $OutputFormat"; Write-Host "[info] Using OutputPath: $OutputPath"; @@ -294,6 +299,10 @@ try { $invokeParams['Option'] = $Option; WriteDebug ([String]::Concat('-Option ', $Option)); } + if (![String]::IsNullOrEmpty($Outcome)) { + $invokeParams['Outcome'] = $Outcome; + WriteDebug ([String]::Concat('-Outcome ', $Outcome)); + } if (![String]::IsNullOrEmpty($Modules)) { $moduleNames = $Modules.Split(',', [System.StringSplitOptions]::RemoveEmptyEntries); $invokeParams['Module'] = $moduleNames; diff --git a/tasks/ps-rule-assertV2/powershell.ts b/tasks/ps-rule-assertV2/powershell.ts index 7ccbf021..a3e5ca2e 100644 --- a/tasks/ps-rule-assertV2/powershell.ts +++ b/tasks/ps-rule-assertV2/powershell.ts @@ -22,6 +22,7 @@ async function run() { let input_baseline: string = task.getInput('baseline', /*required*/ false); let input_conventions: string = task.getInput('conventions', /*required*/ false); let input_option: string = task.getInput('option', /*required*/ false); + let input_outcome: string = task.getInput('outcome', /*required*/ false); let input_outputFormat: string = task.getPathInput('outputFormat', /*required*/ false, /*check*/ false) || 'None'; let input_outputPath: string = task.getPathInput('outputPath', /*required*/ false, /*check*/ false); let input_prerelease: boolean = task.getBoolInput('prerelease', /*required*/ false); @@ -53,6 +54,9 @@ async function run() { if (input_option !== undefined) { contents.push(`$scriptParams['Option'] = '${input_option}'`); } + if (input_outcome !== undefined) { + contents.push(`$scriptParams['Outcome'] = '${input_outcome}'`); + } if (input_outputFormat !== undefined) { contents.push(`$scriptParams['OutputFormat'] = '${input_outputFormat}'`); } diff --git a/tasks/ps-rule-assertV2/task.json b/tasks/ps-rule-assertV2/task.json index 15042452..b83e038d 100644 --- a/tasks/ps-rule-assertV2/task.json +++ b/tasks/ps-rule-assertV2/task.json @@ -100,6 +100,14 @@ "defaultValue": "", "helpMarkDown": "The path to an options file." }, + { + "name": "outcome", + "type": "string", + "label": "Outcome", + "required": false, + "defaultValue": "", + "helpMarkDown": "Filters output to include results with the specified outcome." + }, { "name": "outputFormat", "type": "pickList",