Creating Feature Environments using Merge Request Lifecycle

I’m trying to create feature environments for our development but can’t seem to figure out how to use the CI environment variables in my jobs to manage when they would be created and destroyed.

The details of the environment created are not important I just want to understand how/if I can use GitLab CI to achieve what I want.

The idea I had is:

  1. Event Push Code - Triggers: no action
  2. Event: Create MR - Triggers: Create Feature Environment (infrastructure, db, etc)
  3. Event: Push Code - Triggers: Updates Feature Environment (code)
  4. Event Close/Merge MR - Triggers: Tear Down Feature Environment

How can I identify each of these events in my GitLab CI job?

Thanks in advance.

Note: we are using