GitLab-ci.yml include only includes the first job from the included file

GitLab-ci.yml include only includes the first job from the included file

I’m currently setting up GitLab CI/CD in our repository since it’s been broken from the start, and I want to split up the YML files across multiple files.
This is however causing problems

With a filestructure like this:

  • Root
    • ci/
      • build.gitlab-ci.yml
    • gitlab-ci.yml

Contents of gitlab-ci.yml:

stages:
  - build
  - test
  - deploy

include:
  - local: ci/build.gitlab-ci.yml

Contents of build.gitlab-ci.yml:

build:
  script: echo "Build"

another-build:
  script: echo "Another build"

Then the result in the pipeline editor merged YAML view will be:

build:
  script: echo "Build"
stages:
- ".pre"
- build
- test
- deploy
- ".post"

Notice the lack of the another-build job here.

I’ve already tried various different path definitions but for some reason it just refuses to include anything but the first job in the YML file, putting another-build above build will result in only another-job being included…

Any idea what might be causing this?
I’ve been trying to fix this all of yesterday already and my colleagues have no idea why it does this either.

Versions

  • GitLab: 14.1.5-ce, self-managed
  • Runner: 14.1.0 (although irrelevant in this problem)

Your final stages: list exactly matches the list in your outer file:

If you want any of the included jobs to execute, I think you need to assign them to a configured stage. Try this, in the included file:

build:
  stage: build
  script: echo "Build"

another-build:
  stage: build
  script: echo "Another build"

As far as I understand, without any stage specified they will be assigned to the test stage by default.

I did try adding stage: build to both jobs, but sadly it still will not include the another-build job, I would also think if that was the problem the first build also wouldn’t be included, but it is.

For now I’ve just accepted it not working and put everything in the .gitlab-ci.yaml and it works fine, but I would much prefer splitting the jobs into logical sectioned files for each stage…