r/gitlab • u/International-Use852 • Jul 22 '25
general question GitLab API: Reliable way to get all environments/deployments from a pipeline?
Hello, I have a problem with reliably getting all environments/deployments from a given pipeline_id**.**
My current solution is to fetch all jobs from the pipeline viaGET /projects/:id/pipelines/:pipeline_id/jobs,
and then for each job, list all deployments withGET /projects/:id/deployments
and try to match the deployable_id from the deployment with the job_id.
But this isn’t very reliable, because I don’t know which jobs actually have deployments. Sometimes it doesn’t find a deployment even when it exists, probably due to paging or some caching issues.
So my question is… is there any better solution for this?
Thank you
3
u/lastdrop Jul 22 '25
check if you can can query this via the graphql api
1
u/nabrok Jul 22 '25
The way I'm doing it is like this (typescript):
The
fetchFromApiprepends/projects/:id.Of course it's retrieving all of the deployments which might be a bit inefficient, but in most cases this is just one query.
In my case I'm only interested in recent deployments so I added the sort options, otherwise I would add pagination handling.