thebjorn
thebjorn

Reputation: 27321

Is there an efficient way of finding failed pipelines on gitlab?

I would like to get a list of all projects in a group, where the last pipeline has not succeeded.

My current code:

def failed_pipelines(groupid):
    g = gitlab.Gitlab('https://gitlab.com', private_token=GITLAB_API_TOKEN)
    group = g.groups.get(id=groupid)
    for group_proj in group.projects.list(archived=False, simple=True, as_list=False):
        project = g.projects.get(id=group_proj.id)
        pipelines = project.pipelines.list(page=1, per_page=1)
        if not pipelines:
            continue
        if pipelines[0].status != 'success':
            yield project.name

works, but takes 70+ seconds on 132 projects.

Is there a better/faster way?

Upvotes: 2

Views: 1109

Answers (1)

jwillker
jwillker

Reputation: 1035

Until now have no way to make a request to some object called "pipeline" in a Group scope, because pipelines are project scope, because of this you need to make a lot of requests in a group, one request in each project to be precise, it makes things slow.

You can think in another approach, ex: listing failed jobs in your runners.

runners = g.runners.list(scope='active')

for r in runners:
    job=r.jobs.list(status='failed')
    if job != []:
        print(job)

Upvotes: 2

Related Questions