如何使用 mega-linter 配置文件在 ansible-lint 中不指定目录/文件名的情况下检查整个项目

问题描述 投票:0回答:1
Megalinter 配置中的 ANSIBLE_LINT 启用不会检查 ansible yaml 验证。 在 megainter 配置文件中启用 ansible_lint。输出像这样。

还需要检查目录和子目录内的所有yaml文件,而不指定存储库名称。

截图 Megalinter 配置文件:

其他背景 将 meglinter 作为容器运行:

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=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

我在该目录中有一些错误的 ANSIBLE 格式文件。但它没有提供任何输出。 需要指导才能做到这一点

azure pipeline yaml file

触发:

资源:

存储库:

- repository: self type: git - repository: terraform-pipeline-template type: git name: IaCMasterData/terraform-pipeline-template ref: refs/heads/ansible-lint
工作:

  • 工作:TerraformAndMegalinterExection

    显示名称:Terraform 和 Megalinter 执行

    条件:成功或失败()

    泳池: vmImage:ubuntu-最新

    步骤:

      结帐:自助
    • 签出:terraform-pipeline-template
    • 模板:ansible-security-checks.yml@terraform-pipeline-template
azure-pipelines ansible-lint
1个回答
0
投票
查看所有yaml文件,可以参考以下内容。

    回购“newmegaLinter”:在
  1. 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

    Repo“...-basic”:存储用于创建管道的 yaml 文件。
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 的示例存储库此处。我测试了他的解决方案,效果很好。

© www.soinside.com 2019 - 2024. All rights reserved.