【问题标题】:How to get the total Gitlab CI/CD minutes used from the API?如何从 API 获取使用的 Gitlab CI/CD 总分钟数?
【发布时间】:2023-01-25 06:01:19
【问题描述】:

我正在寻找使用 API 获取用于组的 Gitlab CI/CD 分钟总数。获得小组的剩余配额/分钟数也会很有用。

我在this documentation 上看到了如何从网站上获取它,但它没有指定如何从 API 中获取它。

我还看到了“我可以主动监控我的 CI/CD 分钟使用情况吗?” this page 部分,但它链接到的项目似乎是所有管道,然后汇总它们的持续时间。如果我可以进行一次 API 调用以获取使用的总分钟数,我会更喜欢它。

【问题讨论】:

  • 我们几个人刚才在Git chat room 讨论 GitLab CI/CD。如果你有兴趣,也许我们可以在那里聊天!

标签: gitlab


【解决方案1】:

我现在通过查看 https://gitlab.com/groups/<my group>/-/usage_quotas 页面上网站的 API 调用,设法弄清楚了。

它对 Gitlab GraphQL API 使用这样的查询:

{
    ciMinutesUsage(namespaceId: "gid://gitlab/Group/<group ID>") {
    nodes {
      month
      monthIso8601
      minutes
      projects {
        nodes {
          minutes
          project {
            id
            name
          }
        }
      }
    }
  }
}

响应如下所示:

{
  "data": {
    "ciMinutesUsage": {
      "nodes": [
        {
          "month": "January",
          "monthIso8601": "2023-01-01",
          "minutes": 3,
          "projects": {
            "nodes": [
              {
                "minutes": 3,
                "project": {
                  "id": "gid://gitlab/Project/<project ID>",
                  "name": "Description"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

【讨论】:

    猜你喜欢
    • 2022-06-23
    • 2021-12-24
    • 2023-01-13
    • 2022-07-04
    • 2022-08-14
    • 2020-10-30
    • 2021-03-21
    • 2021-12-22
    • 2020-02-02
    相关资源
    最近更新 更多