Trying to add PSRule testing to Azure Devops pipeline. Pipeline is succeeding, but no tests are running

Viewed 106

I've been working on integrating PSRule into an Azure Devops pipeline. The pipeline is succeeding, but the following error: Target object <FileName> has not been processed because no matching rules were found is being displayed for every file in my repository, at the PSRule stage in the pipeline.

Below, I've included the code for my pipeline. Can anyone help me understand where I've gone wrong with implementing PSRule? Custom rules can be defined, but from my understanding, even without defining any, PSRule should run the 270 or so default rules associated with the module.

trigger:
  batch: true
  branches:
    include:
    - main

pool:
  vmImage: ubuntu-latest

stages:

- stage: Lint
  jobs: 
  - job: LintCode
    displayName: Lint code
    steps:
      - script: |
          az bicep build --file $(MainBicepFile)
        name: LintBicepCode
        displayName: Run Bicep linter

- stage: PSRule
  jobs:
  - job: PSRuleRun
    displayName: PSRule Run
    steps:
      - task: ps-rule-assert@1
        displayName: Analyze Azure template files
        inputs:
          modules: 'PSRule.Rules.Azure'

- stage: Validate
  jobs:
  - job: ValidateBicepCode
    displayName: Validate Bicep code
    steps:
      - task: AzureCLI@2
        name: RunPreflightValidation
        displayName: Run preflight validation
        inputs:
          azureSubscription: $(ServiceConnectionName)
          scriptType: 'bash'
          scriptLocation: 'inlineScript'
          inlineScript: |
            az deployment group validate \
              --resource-group $(ResourceGroupName) \
              --template-file $(MainBicepFile) \

- stage: Preview
  jobs: 
  - job: PreviewAzureChanges
    displayName: Preview Azure changes
    steps:
      - task: AzureCLI@2
        name: RunWhatIf
        displayName: Run what-if
        inputs:
          azureSubscription: $(ServiceConnectionName)
          scriptType: 'bash'
          scriptLocation: 'inlineScript'
          inlineScript: |
            az deployment group what-if \
              --resource-group $(ResourceGroupName) \
              --template-file $(MainBicepFile) \

- stage: Deploy
  jobs:
  - deployment: DeployBicep
    displayName: Deploy Bicep
    environment: 'Test'
    strategy:
      runOnce:
        deploy:
          steps:
            - checkout: self
            - task: AzureCLI@2
              name: DeployBicepFile
              displayName: Deploy Bicep file
              inputs:
                azureSubscription: $(ServiceConnectionName)
                scriptType: 'bash'
                scriptLocation: 'inlineScript'
                inlineScript: |
                  set -e
                  deploymentOutput=$(az deployment group create \
                    --name $(Build.BuildNumber) \
                    --resource-group $(ResourceGroupName) \
                    --template-file $(MainBicepFile))
1 Answers

The warning on by default but not critical to the process after Bicep code has been expanded.

You can disable the warning which shows by default by setting the execution.notProcessedWarning option to false. You can do this in a number of ways however the easiest is to configure it in the ps-rule.yaml option file. See doc for additional options to set this.

Your pipeline configuration is fine however you need to enable expansion for Bicep or parameter files to be processed by the PSRule.Rules.Azure module.

Configuring expansion for Bicep code is done by setting the configuration.AZURE_BICEP_FILE_EXPANSION option to true. This is covered in Using Bicep source.

Hope that helps.

Related