Skip to content

Merging triggers manual environment on_stop action

Summary

Certain projects configured with a action: prepare job for their environments cause other jobs that stop that same environment to be automatically triggered even when they are configured for when: manual.

Steps to reproduce

  1. add this YML to repo in dev branch Create a project with a .gitlab-ci.yml file similar to the one below.
  2. Create a new dev branch.
  3. Run a new pipeline and trigger the Plan DEV and Apply DEV jobs, which deploys an environment.
  4. Create a new merge request into the dev branch.
  5. Merge the MR.
  6. Observe that the manual Stop DEV job is run automatically.
  7. Optionally, comment out the action: prepare line of the Plan DEV job and run a new pipeline.
  8. Observe that the Stop DEV job is not run automatically.
stages:
    - plan
    - apply

image:
    name: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/alpine

Plan DEV:
# Comment out environment and needs and the pipeline will NOT trigger a STOP on a previously deployed environment when you merge into dev branch
    environment:
        name: dev
        action: prepare
    needs: []
    stage: plan
    script:
        - echo "PLAN DEV! ${CI_COMMIT_BRANCH}"
    rules:
        - if: '$CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "main" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"'
          when: never
        - when: on_success

Apply DEV:
    stage: apply
    script:
        - echo "APPLY DEV! ${CI_COMMIT_BRANCH}"
    environment:
        name: dev
        on_stop: Stop DEV
    dependencies:
        - Plan DEV
    rules:
        - if: $CI_COMMIT_BRANCH
          when: manual

Stop DEV:
    stage: apply
    script:
        - echo "STOP DEV! ${CI_COMMIT_BRANCH}"
    environment:
        name: dev
        action: stop
    rules:
        - if: $CI_COMMIT_BRANCH
          when: manual

What is the current bug behavior?

Jobs that stop an environment are automatically run in the presence of the action: prepare keyword.

What is the expected correct behavior?

Jobs that are defined to run manually should not be triggered automatically.

Output of checks

This bug happens on GitLab.com: 14.5.0-pre 9df5f28f557