Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adds needs relations to GitLab CI yaml but got an error: the job was not added to the pipeline

I am trying to add needs between jobs in the Gitlab CI yaml configuration file.


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, 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.

Update: Finally I made it. I think the needs position is sensitive, move all needs under the stage, it works. My original scripts included some other configuration between them.

like image 308
Hantsy Avatar asked Apr 22 '21 10:04

Hantsy


2 Answers

CI-jobs that depend on each other need to have the same limitations!

In your case that would mean to share the same only targets:

stages:
  - build
  - test

maven-build:
  stage: build
  only:
    - merge_requests
    - master
    - branches

test:
  stage: test
  needs: [ "maven-build" ]
  only:
    - merge_requests
    - master
    - branches

that should work from my experience^^

like image 60
dniwdeus Avatar answered Oct 25 '22 16:10

dniwdeus


Finally I made it. I think the needs position is sensitive, move all needs under the stage, it works

Actually... that might no longer be the case with GitLab 14.2 (August 2021):

Stageless pipelines

Using the needs keyword in your pipeline configuration helps to reduce cycle times by ignoring stage ordering and running jobs without waiting for others to complete.

Previously, needs could only be used between jobs on different stages.

In this release, we’ve removed this limitation so you can define a needs relationship between any job you want.

As a result, you can now create a complete CI/CD pipeline without using stages by including needs in every job to implicitly configure the execution order.
This lets you define a less verbose pipeline that takes less time to create and can run even faster.

https://about.gitlab.com/images/14_2/need.png -- Stageless pipelines

See Documentation and Issue.

like image 26
VonC Avatar answered Oct 25 '22 16:10

VonC