Jobs in subsequent stages triggered regardless of initial failures when `needs` is used

Summary

When defining jobs with needs even though the previous job did not run due to an earlier failure in the pipeline continues and jobs are unexpectedly executed (https://gitlab.com/paulbry/runner-scratch/pipelines/113702230). Additionally, behavior is apparent when rules (when: on_success) are introduced and the failure in the first stage does not prevent other jobs from running (https://gitlab.com/paulbry/runner-scratch/pipelines/114035234).

Note, I wasn't able to find any existing issue or post regarding this behavior; however, if I missed something please let me know.

Steps to reproduce

In at least a three-stage pipeline have a job on the first stage fail. The second stage will have job(s) that job(s) in the third stage rely upon using the needs feature. Please see the associated example projects for more details.

Example project (from: https://gitlab.com/paulbry/runner-scratch/tree/test-needs)

stages:
  - prepare
  - build
  - test
  - deploy

image: alpine

prep:
  stage: prepare
  script:
    - echo "${CI_JOB_NAME}"
    - exit 1

build:1:
  stage: build
  script:
    - echo "Building"

build:2:
  stage: build
  script:
    - echo "Building"

test:1:
  stage: test
  script:
    - echo "Testing"
  needs: ["build:1"]

test:2:
  stage: test
  script:
    - echo "Testing"
  needs: ["build:2"]

deployment:
  stage: deploy
  script:
    - echo "Deploying"

Example Project

I have create an example project with two branches that demonstrate the current behavior.

  • https://gitlab.com/paulbry/runner-scratch/tree/test-needs
  • https://gitlab.com/paulbry/runner-scratch/tree/test-needs-rules

What is the expected correct behavior?

I would expect that in either case the failure of a job in the first stage, due to a lack of allow_failure, would prevent jobs found in the subsequent stages from being run.

Relevant logs and/or screenshots

In both instance a failure is caused in the first stage by an exit 1 in the script.

Using just needs between build/test:

image

Creating a slightly expanded example that more closely aligns to behaviors I saw on another project I've included rules and passed artifacts between the build/test stages. Due to the build stage job never running obviously the missing artifacts cause the test stage jobs to fail.

image

Output of checks

This bug happens on GitLab.com

Results of GitLab environment info

This bug happens on GitLab.com

Results of GitLab application Check

This bug happens on GitLab.com

Assignee Loading
Time tracking Loading