我一直致力于将PSRule集成到Azure Devops管道中。管道成功了,但是出现了以下错误:在管道中的PSRule阶段,我的存储库中的每个文件都显示了Target object <FileName> has not been processed because no matching rules were found
。
下面,我包含了管道的代码。谁能帮助我了解我在哪里错了实现PSRule?可以定义自定义规则,但根据我的理解,即使没有定义任何规则,PSRule也应该运行与模块关联的270个左右的默认规则。
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))
该警告默认为打开,但在扩展了Bicep代码后对进程不重要。
通过将execution.notProcessedWarning
选项设置为false
,可以禁用默认显示的警告。您可以通过多种方式实现这一点,但是最简单的方法是在ps-rule.yaml
选项文件中配置它。
您的管道配置很好,但是您需要启用扩展Bicep或参数文件,以便由PSRule.Rules.Azure模块处理。
通过将configuration.AZURE_BICEP_FILE_EXPANSION
选项设置为true
来配置Bicep代码的扩展。这在使用Bicep源代码中有介绍。
希望对你有帮助。