'when: always' job runs as soon as a single 'needs' dependency is skipped

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

  • Close this issue

Summary

I have a job with when: always, which has multiple needs dependencies on other jobs. When one of those jobs is skipped (due to a previous job failing for example), the job is executed immediately, without waiting for other dependencies to finish.

Steps to reproduce

The following ci file illustrates the issue:

.gitlab-ci.yml
stages:
- a
- b
- c

first-job-a:
  stage: a
  script:
    - sleep 10
    - exit 1

first-job-b:
  stage: b
  needs:
    - job: first-job-a
  script:
  # Should never run
    - exit 1

second-job:
  stage: b
  needs: []
  script:
    - sleep 600
    - exit 0

third-job:
  stage: c
  when: always
  needs:
    - job: first-job-b
    - job: second-job
  script:
    - echo "Test"

As you can see here, third-job job is already running while second-job is still in progress:

image

Example Project

https://gitlab.com/fxshlein/pipeline-bug-reproducer

Pipeline: https://gitlab.com/fxshlein/pipeline-bug-reproducer/-/pipelines/1473823060

What is the current bug behavior?

The third-job job is started right after the dependency is skipped.

What is the expected correct behavior?

The third-job job is started only after all dependencies are either succeeded, failed or skipped.

Interestingly, this is also the behavior when removing the intermediate job. third-job waits for second-job, even though first-job has failed:

image

.gitlab-ci.yml without intermediate job
stages:
- a
- b

first-job:
  stage: a
  script:
    - sleep 10
    - exit 1

second-job:
  stage: a
  script:
    - sleep 600
    - exit 0

third-job:
  stage: b
  when: always
  needs:
    - job: first-job
    - job: second-job
  script:
    - echo "Test"

Output of checks

Possible fixes

Edited Jun 16, 2025 by 🤖 GitLab Bot 🤖
Assignee Loading
Time tracking Loading