Include external files in gitlab-ci file

Viewed 27

I am trying to make a shared pipeline repository, from where I am running a Dangerfile. The cool thing here should be that each repo could simply include the shared-pipeline repo's Dangerfile and .gitlab-ci.yml-file and then get all the cool stuff from it. My problem is, from repo1 I am trying to use include to inherit the Dangerfile from repository shared-pipeline. However, it is only possible to include .yaml files. I can include .gitlab-ci.yml, but how do I include external files such as the Dangerfile?

├── shared-pipeline
│   ├── Dangerfile
│   └── .gitlab-ci.yml
├── repo1
│   └── .gitlab-ci.yml
├── repo2
│   └── .gitlab-ci.yml
└── repo3
    └── .gitlab-ci.yml

This is what I have so far:

include:
  - project: 'myproject/shared-pipeline'
    file: '.gitlab-ci.yml'

This is what I was trying:

include:
  - project: 'myproject/shared-pipeline'
    file: '.gitlab-ci.yml'
  - project: 'myproject/shared-pipeline'
    file: 'Dangerfile' # Syntax error here as this is no yml file
1 Answers

you can not include other files than yml files. GitLab will merge your included yml files to one big file and will execute it on the runners.

This will just fetch the content of the file and merge it. If you do want to use a file from your shared pipeline, you do have multiple options:

  1. put it in a shared docker image, which will be used by your action, this way everyone will get the same dangerfile with the docker image executed in the job.
  2. fetch the docker image via API in a pre step and make it available to your job with the artifact directive
  3. you could also put the file in a separate docker image, and use the artifact directive in an earlier step to hand it over.
  4. ... and most likely many more

... but to be clear again, you can not use the include directive to include any kind of file into your pipeline.

Related