5

I've been trying to get more familiar with GitLab's CI functionality and find the idea of splitting up a CI pipeline into multiple separate jobs interesting. This would allow me to maintain one project of "known jobs" and include them in other projects.

So far, I have something like this:

$ ls
jobA.yaml jobB.yaml jobC.yaml jobD.yaml

Those 4 are all identical (for now), and have the following:

job-name:
   stage: my-stage # Might be needed to differentiate later on
   tags: runner-tag # used to figure out where/how the job should be done: directly on a server, in a container, etc
   script:
      - echo "beep beep"

In the actual .gitlab-ci.yaml I want to use, I would then (I think) put something like this. In this case, I would use the jobs defined in the project for itself:

include:
        project: '$CI_PROJECT_PATH'
        file: "*.yaml"
stages:
  - my-stage

That gives me back a linter error though. Perhaps I'm misreading the documentation, but I think that should be possible somehow....

pgierz
  • 674
  • 3
  • 7
  • 14

2 Answers2

5

According to the docs, wildcard includes are only possible with local. Furthermore you need to move your jobA.yaml to a directory as otherwise you will include your .gitlab-ci.yml as well with a wildcard on the top level.

So the following works with JobA.yaml in config:

include:
  - local: 'config/*.yaml'

stages:
  - my-stage
danielnelz
  • 3,794
  • 4
  • 25
  • 35
4

This should be a comment, but can't put formatted code in there..

We use a main yml, which just include all the others. It is not wildcards like you have.

Have you tried changing "file" to "local"? with the leading "- "?

include:
  - template: Code-Quality.gitlab-ci.yml
  - local: '/.gitlab/py.yml'
  - local: '/.gitlab/static.yml'
  - local: '/.gitlab/lint.yml'
  - local: '/.gitlab/docs.yml'
  - local: '/.gitlab/publish.yml'
sur.la.route
  • 440
  • 3
  • 11