Skip to content

A job with needs keyword is run even if needed job is skipped

Summary

When using the keyword needs, a skipped job trigger execution of those which need it.

Steps to reproduce

Use the following CI configuration:

stages:
  - check
  - build
  - test

lint:
  stage: check
  script:
    - echo "static check on code"
    - exit 1

docker_ci_image:
  stage: build
  script:
    - echo "build & push docker image"

unittest:
  stage: test
  script:
    - echo "run test using docker image"
  needs:
    - docker_ci_image

In a general way, it happen if a job in a previous stage of a needed one fail, leading it to be marked as skipped.

Example Project

https://gitlab.com/Tassatux/ci-test

An example of failing pipeline: https://gitlab.com/Tassatux/ci-test/pipelines/79899004

What is the current bug behavior?

When a job mentioned with needs keyword is skipped (docker_ci_image in previous example) due to a previous failing stage for instance, all jobs that need it are run.

What is the expected correct behavior?

Jobs that need the skipped one (unittest in previous example) should be skipped too, as they will in traditional stage-based pipeline.

Relevant logs and/or screenshots

image

image

Output of checks

This bug happens on GitLab.com


I'm not sure this should be considered as a bug, but it's the behavior I excepted when reading the DAG documentation.

There no really a big impact on my use case, as the Docker image I except in later jobs didn't exist so the job fail early, I have multiple failed jobs instead of one and others skipped in classical pipeline.