Skip to content

How can we pass dynamic values to a custom rule? can we create a rule with parameters like we create a function with parameters? #1115

Answered by BernieWhite
ankur90Git asked this question in Q&A
Discussion options

You must be logged in to vote

@ankur90Git Thanks for the question.

Currently there isn't a global variable or parameters concept in PSRule, however there is an option to use configuration. Configuration works for PowerShell-based rules but we are looking at YAML and JSON rule support. This should achieve what you are looking for.

You can set configuration key/values in code, file (via ps-rule.yaml), or environment variables depending on how you are running PSRule one of these options should work.

See Options for the full details on how to do this.

You could update your rule to be something like:

# Synopsis: key FUNCTIONS_WORKER_RUNTIME must have value 'dotnet'
Rule 'FUNCTIONS_WORKER_RUNTIME' {
    AllOf {
        Exists 

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ankur90Git
Comment options

@BernieWhite
Comment options

Answer selected by ankur90Git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants