Using Deployments API to determine latest SHA of an environment

Hi, I’m trying to programmatically determine the latest SHA deployed to a Gitlab “environment”. I’m running into some trouble, though, and I’m wondering if anyone has any ideas.

  1. The environments API does not expose the latest SHA deployed to that environment, so it is to use the deployments API.
  2. Using the deployments API, you’d have to list all deployments, then parse out the latest deployment with environment.name = “your-environment” name, and extract the SHA. This is doable, however, it appears that the deployments list API (for example https://mygitlab.com/api/v4/projects/440/deployments) returns an incomplete set of deployments. I am only getting a list 17 deployments, starting with the oldest. My newest deployments are not listed. It appears there is a limit on the number of deployments that are returned… And the API doesn’t provide a way to filter or sort what gets returned.

So I am kind of stuff here… Thanks for any help here.

-Dan

1 Like

It will be nice if the Deployments API supports just returns the latest deployment of all envs or specific env.
Something like:
https://mygitlab.com/api/v4/projects/440/deployments/envs/latest
https://mygitlab.com/api/v4/projects/440/deployments/envs/myenv/latest

I am facing the same issue