【问题标题】:Getting pipeline ID after triggering that pipeline in Gitlab在 Gitlab 中触发该管道后获取管道 ID
【发布时间】:2021-11-26 13:23:26
【问题描述】:

我使用 Gitlab CI/CD 来部署我的项目。我使用 Gitlab REST API 来操作管道。 对于启动管道,我可以使用此端点:

POST /projects/:id/trigger/pipeline

对该请求的响应如下:

{
    "ref": "master_branch",
    "status": "pending"
}

.. 和触发的管道 ID 无关。

我还想知道一些关于触发管道的信息:

GET /projects/:id/pipelines/:pipeline_id

.. 但我不知道管道 ID。

是的,我知道GET /projects/:id/pipelines 的管道列表,但这不是我真正想要的。

如何知道触发管道ID?

【问题讨论】:

    标签: gitlab gitlab-api


    【解决方案1】:

    对Create Pipeline API 操作的响应会为您提供实例范围的管道 ID(称为 id)和特定于项目的 ID(称为 iid),id 就是您所看到的在项目的 Pipelines 列表中以及您将在其他 API 调用中使用的内容中。

    这是来自docs 的示例响应:

    {
      "id": 61,
      "iid": 21,
      "project_id": 1,
      "sha": "384c444e840a515b23f21915ee5766b87068a70d",
      "ref": "main",
      "status": "pending",
      "before_sha": "0000000000000000000000000000000000000000",
      "tag": false,
      "yaml_errors": null,
      "user": {
        "name": "Administrator",
        "username": "root",
        "id": 1,
        "state": "active",
        "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
        "web_url": "http://localhost:3000/root"
      },
      "created_at": "2016-11-04T09:36:13.747Z",
      "updated_at": "2016-11-04T09:36:13.977Z",
      "started_at": null,
      "finished_at": null,
      "committed_at": null,
      "duration": null,
      "queued_duration": 0.010,
      "coverage": null,
      "web_url": "https://example.com/foo/bar/pipelines/61"
    }
    

    【讨论】:

    • 感谢您的帮助。实际上,在我的情况下,最好使用创建管道 api 而不是触发管道。
    猜你喜欢
    • 2022-09-27
    • 2020-06-14
    • 2021-11-15
    • 2022-01-09
    • 1970-01-01
    • 2022-11-15
    • 1970-01-01
    • 2021-03-11
    • 2019-11-19
    相关资源
    最近更新 更多