还需要检查目录和子目录内的所有yaml文件,而不指定存储库名称。
截图 Megalinter 配置文件:
其他背景 将 meglinter 作为容器运行:
docker run -v $(System.DefaultWorkingDirectory):/tmp/lint --env-file我在该目录中有一些错误的 ANSIBLE 格式文件。但它没有提供任何输出。 需要指导才能做到这一点<(env | grep -e SYSTEM_ -e BUILD_ -e TF_ -e AGENT_) -e SYSTEM_ACCESSTOKEN=$(System.AccessToken) -e GIT_AUTHORIZATION_BEARER=$(System.AccessToken) -e MEGALINTER_CONFIG=terraform-pipeline-template/.mega-linter.yml -e PROJECT_DIR=Networking -e ANSIBLE_DIRECTORY=. -e CONSOLE_REPORTER_SECTIONS=true -e OUTPUT_DETAIL=detailed -e JSON_REPORTER_OUTPUT_DETAIL=detailed -e JSON_REPORTER_FILE_NAME=mega-linter-report.json -e AZURE_COMMENT_REPORTER_LINKS_TYPE=builds -e REPORTERS_MARKDOWN_TYPE=advanced -e SYSTEM_PULLREQUEST_PULLREQUESTID=$(System.PullRequest.PullRequestId) --name megalinter oxsecurity/megalinter:v7
触发:
存储库:
- repository: self
type: git
- repository: terraform-pipeline-template
type: git
name: IaCMasterData/terraform-pipeline-template
ref: refs/heads/ansible-lint
工作:
显示名称:Terraform 和 Megalinter 执行
条件:成功或失败()
泳池: vmImage:ubuntu-最新
步骤:
ansible-security-checks.yml
分支中存储
.mega-linter.yml
和
main
。
-e MEGALINTER_CONFIG=newmegaLinter/.mega-linter.yml
指定
ansible-security-checks.yml
中的配置文件。
#ansible-security-checks.yml
steps:
# Pull MegaLinter docker image
- script: docker pull oxsecurity/megalinter:v7
displayName: Pull MegaLinter
# Run MegaLinter
- script: |
docker run -v $(System.DefaultWorkingDirectory):/tmp/lint \
--env-file <(env | grep -e SYSTEM_ -e BUILD_ -e TF_ -e AGENT_) \
-e SYSTEM_ACCESSTOKEN=$(System.AccessToken) \
-e GIT_AUTHORIZATION_BEARER=$(System.AccessToken) \
-e MEGALINTER_CONFIG=newmegaLinter/.mega-linter.yml \
oxsecurity/megalinter:v7
displayName: Run MegaLinter
# Upload MegaLinter reports
- task: PublishPipelineArtifact@1
condition: succeededOrFailed()
displayName: Upload MegaLinter reports
inputs:
targetPath: "$(System.DefaultWorkingDirectory)/megalinter-reports/"
artifactName: MegaLinterReport
.mega-linter.yml
,将
ENABLE
设置为
YAML
,将
ENABLE_LINTERS
设置为
YAML_YAMLLINT
。您可以使用
FILTER_REGEX_INCLUDE
和
FILTER_REGEX_EXCLUDE
仅对文件夹进行 linting 或从 linting 中排除某些文件。
#.mega-linter.yml
ENABLE: # If you use ENABLE variable, all other languages/formats/tooling formats will be disabled by default
- YAML
ENABLE_LINTERS: # If you use ENABLE_LINTERS variable, all other linters will be disabled by default
- YAML_YAMLLINT
VALIDATE_ALL_CODEBASE: true
PRINT_ALL_FILES: true
#FILTER_REGEX_EXCLUDE: '(newmegaLinter/)'
YAML_YAMLLINT_FILTER_REGEX_EXCLUDE: '(templates/\.mega-linter\.yml)'
SHOW_ELAPSED_TIME: true
FLAVOR_SUGGESTIONS: false
EMAIL_REPORTER: false
FILEIO_REPORTER: false
AZURE_COMMENT_REPORTER: true
trigger:
- none
resources:
repositories:
- repository: newmegaLinter
name: newmegaLinter
ref: refs/heads/main
type: git
jobs:
- job: MegalinterExection
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
- checkout: newmegaLinter
- template: ansible-security-checks.yml@newmegaLinter
运行管道,我可以看到MegaLinter检查的所有yaml文件。
上述方法将检查所有yaml文件,并需要为每个源存储库创建一个管道。如果你需要检查很多仓库,这可能会很麻烦。您可以专门为 MegaLinter 创建管道并使用分支策略来检查每个存储库。请参阅实现代码一致性:Azure DevOps 中的 MegaLinter 集成 中的详细信息,并参阅 Don 的示例存储库此处。我测试了他的解决方案,效果很好。