The `needs` rule does not work as expected

The original post was created on Stackoverflow, but I can not get the solution there.

Hope this forum is a better place to ask Gitlab related questions.

I tried to add needs between jobs in the Gitlab CI configuration file, the code structure is similar to th e following.


stages:
  - build
  - test
  - package
  - deploy

maven-build:
  stage: build
  only:
    - merge_requests
    - master
    - branches
  ...
test:
  stage: test
  needs: [ "maven-build" ]
  only:
    - merge_requests
    - master
  ...
docker-build:
  stage: package
  needs: [ "test" ]
  only:
    - master
  ...
deploy-stage:
  stage: deploy
  needs: [ "docker-build" ]
  only:
    - master
  ...
deploy-prod:
  stage: deploy
  needs: [ "docker-build" ]
  only:
    - master
  when: manual
  ...

I have used the GitLab CI online lint tools to check my syntax, it is correct.

But when I pushed the codes to trigger the CI pipelines, it always complains:


    'test' job needs 'maven-build' job
    but it was not added to the pipeline

You can also test your .gitlab-ci.yml in CI Lint

The GitLab CI did not run at all.

Hi,

Can you clarify on the steps a bit more - which Git branches are involved? What is needed to reproduce the problem, i.e. can you create a standalone configuration which allows others to reproduce the problem?

Does it work when you remove the only clause from the maven-build job?

Which GitLab version are you using?

Cheers,
Michael

I used online Gitlab.com.

This is exactly our problem. Let me summarize the bug, and fix.

If job Y needs job X (because of a needs clause), and job Y runs, then gitlab-ci has all the information required to force job X to run.

But it doesn’t force X to run.

Instead, we need to work around your bug by larding up X with only clauses to force X to run, anytime Y might run.

The proper fix is for GitLab to force X to run when Y runs, and Y needs X.