How to prevent automatic running of environment stop job on issue branch deletion?

I have started using environments and I want to be able to keep a CI environment going while different feature/issue branches are created and deleted. Currently, a ci-deployment job defines our ‘ci’ environment and is run only when feature/issue branches are pushed. The master branch is protected and is updated only through merge requests in the UI. When I merge an issue branch to the master branch and automatically delete the issue branch the stop job is invariably run, even though it is explicitly configured to be manual. How do I stop auto-stop-on-branch-deletion?

Here’s how the jobs are configured:

stages:
  ...
  - deploy
  - stop

deploy_ci:
  except:
    - tags
    - master
  stage: deploy
  script:
    - echo "deploy the environment..."
  environment:
    name: ci
    on_stop: stop_ci

stop_ci:
  except:
    - tags
    - master
  stage: stop
  when: manual
  script:
    - echo "stop the environment..."
  environment:
    name: ci
    action: stop

What I expect to happen:
The environment stop job should never run unless I press the ‘stop’ button in the UI because it is configured as ‘when: manual’.

What actually happens:
When I merge N-feature-branch to master with the ‘delete branch’ checkbox checked, the ‘stop_ci’ job is automatically run.

According to the documentation, the stop job shouldn’t be running if it is in a different stage from the deploy job.

I tried removing the ‘on_stop: stop_ci’ line from the config and the desired behavior of not stopping the environment on branch deletion happened, but the full capability of environments doesn’t work:

  • stop button isn’t configured in Environments UI
  • environment stays in the ‘stopped’ tab in Environments page even after clicking the ‘re-deploy to environment’ button

Because our particular application is tied to one database per environment (ci/staging/prod), and only one installation can access its environment’s database at a time, it isn’t possible to use the ‘review apps’ paradigm.

From what I can tell using review apps for a few months now, this is the intended behavior. The system automatically calls stop under certain circumstances, for example: closing or merging an MR or, as you’ve seen, deleting a branch.

The when: manual flag is really only respected for normal pipelines.

You might open an issue with support.gitlab.com or get help from them to request a change.