How to get a list of all pipelines run for gitlab scheduled pipeline

Viewed 112

I have a scheduled pipeline setup in gitlab, but when I query it, it only shows the last run pipeline. I would like to be able to get a list of all of the pipelines it has run so I can perform some analysis on them. I tried looking into both the rest and graphql apis and I didn't seem to find anything that would solve this. Is there a way to do this?

1 Answers

You can actually list all pipelines triggered by schedule using GitLab REST API

GET /projects/:id/pipeline_schedules/:pipeline_schedule_id/pipelines

Your request attributes must contain the project id and the pipeline_schedule_id as both are required. You could replace the project id with the URL-encoded path of your owned projects.

Example Request:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules/13/pipelines"

Example Response:

[
  {
    "id": 47,
    "iid": 12,
    "project_id": 29,
    "status": "pending",
    "source": "scheduled",
    "ref": "new-pipeline",
    "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
    "web_url": "https://example.com/foo/bar/pipelines/47",
    "created_at": "2016-08-11T11:28:34.085Z",
    "updated_at": "2016-08-11T11:32:35.169Z"
  },
  {
    "id": 48,
    "iid": 13,
    "project_id": 29,
    "status": "pending",
    "source": "scheduled",
    "ref": "new-pipeline",
    "sha": "eb94b618fb5865b26e80fdd8ae531b7a63ad851a",
    "web_url": "https://example.com/foo/bar/pipelines/48",
    "created_at": "2016-08-12T10:06:04.561Z",
    "updated_at": "2016-08-12T10:09:56.223Z"
  }
]

Reference link https://docs.gitlab.com/ee/api/pipeline_schedules.html#get-all-pipelines-triggered-by-a-pipeline-schedule

Related