0

Currently, I am creating GitLab environments for each merge request to deploy temporary pages. These environments stop as soon as merge request is merged, but I want to add an additional step to the pipeline to "Remove environment" completely from "Stopped" environments. I don't want to use GUI and only option I found was an API method:

DELETE /projects/:id/environments/:environment_id

https://docs.gitlab.com/ee/api/environments.html#delete-an-environment

But, problem here is that it required :environment_id variable, which I couldn't manage to find and get.

Any help with a different approach or how to get :environment_id will be appreciated.

DemiA
  • 333
  • 1
  • 11

1 Answers1

0

You can schedule for deletion all stopped review apps environment :

DELETE /projects/:id/environments/review_apps

Or you can list your environments and search for the one you need to delete with name or search param. Then you can get the environment_id to delete that environment. You can add the states param to get only stopped environments :

GET /projects/:id/environments?states=stopped&name=review%2Fxxx

Then just make a loop on the result to call the DELETE endpoint. You can use jq to get the environment_id in the result.

fmdaboville
  • 1,394
  • 3
  • 15
  • 28
  • That is using the API, but I don't have an opportunity to use JavaScript. Only pipeline scripts :( – DemiA Jun 13 '22 at 07:49
  • You can make some api call during the pipeline script. And you mentionned API, that is why I suggest you to use it. – fmdaboville Jun 13 '22 at 13:09