2

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
thebjorn
  • 26,297
  • 11
  • 96
  • 138

1 Answers1

2

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)

jwillker
  • 975
  • 9
  • 12