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.
- list the environments and get the pipeline ID Environments API | GitLab
- list MR pipelines Merge requests API | GitLab
- match the pipeline ID and return the environment URL
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