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:

  - deploy
  - stop

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

    - tags
    - master
  stage: stop
  when: manual
    - echo "stop the 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 or get help from them to request a change.

Hi @simeonberkley,
I actually have the same issue and I don’t even delete my branch.
I only merge develop to staging without deleting the develop branch and yet, it stops my develop environment.

Have you found a solution besides removing on_stop?
I’d really appreciate your help