How to convert PSRule output to structured objects or formatted string. #1266
-
I would like to know if it is possible to format the output of PSRule (Assert-PSRule or Invoke-PSRule) to either structured objects or formatted string. My use case.In an Azure pipeline I execute PSRule to validate my templates (pre commit build validation). PSRule is to be run via PowerShell script only. This can be accomplished by running both Assert-PSRule and Invoke-PSRule. However, I do not want to run the rule validation twice. If this is currently not possible it would be great when this functionality could be added to the cmdlet. SuggestionPerhaps a [PSRule.Configuration.PSRuleOption]$psRuleOptions = New-PSRuleOption -Configuration @{ AZURE_BICEP_FILE_EXPANSION = $true }
[PSRule.Rules.RuleRecord[]]$PSRuleResults = Assert-PSRule -InputPath .\Templates\storage.bicep -Module PSRule.Rules.Azure -Format File -Outcome All -Path .\.ps-rule\ -Option $PSRuleOptions -Culture en -OutputPath .\results\__PSRuleResults.xml -OutputFormat NUnit3 -Passthrough |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
@Marc013 Thank you for the question. Yes, you can do this. An additional parameter ( For example: [PSRule.Configuration.PSRuleOption]$psRuleOptions = New-PSRuleOption -Configuration @{ AZURE_BICEP_FILE_EXPANSION = $true }
Assert-PSRule -InputPath .\Templates\storage.bicep -Module PSRule.Rules.Azure -Format File -Outcome All -Path .\.ps-rule\ -Option $PSRuleOptions -Culture en -OutputPath .\results\__PSRuleResults.xml -OutputFormat NUnit3 -ResultVariable results
# Get results
$results See https://microsoft.github.io/PSRule/v2/commands/PSRule/en-US/Assert-PSRule/. I hope that answers your question. |
Beta Was this translation helpful? Give feedback.
@Marc013 Thank you for the question. Yes, you can do this. An additional parameter (
-ResultVariable
) exists onAssert-PSRule
for this reason.For example:
See https://microsoft.github.io/PSRule/v2/commands/PSRule/en-US/Assert-PSRule/.
I hope that answers your question.