I am trying to fetch the latest review app (environment) for a given merge request via the API. Is there some way to achieve this?
I thought I might be able to do what happens in the UI, namely to find the latest pipeline and get the environments for that, but I don’t seem to be able to find any relevant pieces of data in the API docs for the response for any of the objects that would allow me to tie them together.
I haven’t done this before - I think that the other way around could work, starting at the environments and “join” them with MR pipelines that are deployed into the environment.
Looking at python-gitlab, for more code alike suggestions.
Thinking of the following algorithm in Python code. I haven’t tested it, lacking a test environment. Hope it helps with your own implementation.
mr_id = 1234
mr = project.mergerequests.get(mr_id)
pipelines = mr.pipelines.list()
environments = project.environments.list()
for p in pipelines:
for e in environments:
if p.id == e.pipeline.id:
print("Found MR %d in pipeline %d and environment URL %s" % (mr_id, p.id, e. web_url))
sys.exit(0)
# found nothing, maybe exit with an error
Thanks, this is really helpful. I’ll give it a shot
1 Like