Gitlab-ci does run all stop jobs while using auto_stop_in with many deploy jobs

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

  • Close this issue

When using the following .gitlab-ci.yml only one of the 'stop' job is executed, usually the one that correspond to the last 'deploy' job.

How to reproduce:

  • create a merge request with this .gitlab-ci.yml
  • wait for .pre and build stage to finish
  • deploy deps (because apps require it)
  • deploy the api
  • deploy the workers
  • wait for timer for the stop jobs to kick in
  • only last, stop workers job is executed

Expected behavior:

  • all the stop job (deps, api and workers) are run when the timer kicks in, not only the last one
# Pre jobs
pre:
  stage: .pre
  only:
  - merge_requests
  script:
  - echo 'I am .pre job'

# Build jobs
build:
  stage: build
  only:
  - merge_requests
  script:
  - echo 'I am build job'

# Deploy jobs
.deploy template:
  when: manual
  stage: deploy
  variables:
    COMPONENTS: 'override me'
  script:
  - echo 'Deploying ${COMPONENTS}'
  rules:
  - if: $CI_MERGE_REQUEST_ID
    when: manual

deploy deps:
  extends: .deploy template
  variables:
    COMPONENTS: 'deps'
  before_script:
  - echo 'I should be run before deploying any apps'
  environment:
    name: testenv
    on_stop: stop deps
    auto_stop_in: 1 hour

deploy api:
  extends: .deploy template
  variables:
    COMPONENTS: 'api'
  environment:
    name: testenv
    on_stop: stop api
    auto_stop_in: 1 hour
  needs:
  - job: deploy deps

deploy workers:
  extends: .deploy template
  variables:
    COMPONENTS: 'workers'
  environment:
    name: testenv
    on_stop: stop workers
    auto_stop_in: 1 hour
  needs:
  - job: deploy deps

# Stop jobs
.stop template:
  when: manual
  stage: deploy
  variables:
    COMPONENTS: ''
  script:
  - 'echo "Stopping ${COMPONENTS}"'
  environment:
    name: testenv
    action: stop
  rules:
  - if: $CI_MERGE_REQUEST_ID
    when: manual

stop deps:
  extends: .stop template
  variables:
    COMPONENTS: 'deps'

stop api:
  extends: .stop template
  variables:
    COMPONENTS: 'api'

stop workers:
  extends: .stop template
  variables:
    COMPONENTS: 'workers'
Edited Jul 27, 2025 by 🤖 GitLab Bot 🤖
Assignee Loading
Time tracking Loading