【问题标题】:How to parse all the .gitlab-ci.yml files from all the repositories that i have access to?如何解析我有权访问的所有存储库中的所有 .gitlab-ci.yml 文件?
【发布时间】:2021-12-31 05:33:37
【问题描述】:

如何从我有权访问的所有存储库中解析所有 .gitlab-ci.yml 文件? 我正在搜索文档以使用 python 脚本执行此操作,但没有运气。

非常感谢任何建议。提前谢谢各位!

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: python gitlab yaml


【解决方案1】:

您可以使用 API 来做到这一点。

首先,您使用projects 端点检索所有项目。 应该是这样的(这些是 curl 示例,因为我不知道 python,但我希望你知道它们该怎么做)

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects?membership=true"

然后您循环访问响应,并为每个项目使用repository files endpoint 来获取 gitlab-ci.yaml。

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/13083/repository/files/gitlab-ci%2Eyaml?ref=master"

那么你只需要一个好的 YAML 解释器,这里应该已经回答了:How can I parse a YAML file in Python

编辑:对于像我一样不懂python的人来说,这似乎对如何在python中调用restful API很有帮助:Making a request to a RESTful API using python

【讨论】:

    猜你喜欢
    • 2017-03-19
    • 2018-06-11
    • 2021-04-24
    • 1970-01-01
    • 1970-01-01
    • 2021-04-24
    • 2021-08-24
    • 1970-01-01
    • 2022-11-22
    相关资源
    最近更新 更多