Recommendation on templating

Hi all,

I’m currently looking to reduce the amount of duplicate code and the upkeep required for our pipelines. Currently we have about 18 pipelines which all depend on the install of npm and node_modules, I’m trying to find the best solution to be able to cut this duplicated code down and instead have it in one location which can be retrieved from each of the pipelines. Would something like an Instance template repository be best for this? or perhaps another method…

I did try the include: function as described here: https://docs.gitlab.com/ee/ci/yaml/includes.html but when trying I seem to get the following errors from the CI lint- ‘Included file is empty or does not exist!’ or ‘Included file does not have valid YAML syntax!’

Any help would be greatly appreciated!

Cheers

John

Hi,

the point to includes is a good one. In order to reproduce and understand the error message better, please do share the CI config parts as well as locations of these included files.

Cheers,
Michael

Hey Michael,

We are just testing the water with the includes function; to start off I was trying this:

Within the .gitlab-ci.yml file I have added

include:

I also tried formatting it like this

include: ‘https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml

Am I missing something in the back-end? Does this feature need enabling within Gitlab, or is it a premium feature we don’t have access to?

Thanks in advance

John

bump bump

Hi,

please don’t bump topics, this makes the topic unreadable over time. Those watching and reading receive their notifications with just a single reply. I have a long TODO list and your reply was not lost just stuck.

In terms of referencing an existing CI template, just a few recommendations:

Now, let’s try this together.

This one fails.

# Test template includes
include:
  - template: Build.gitlab-ci.yml

The template does not exist in the given location at https://gitlab.com/gitlab-org/gitlab/tree/master/lib/gitlab/ci/templates

# Test template includes
include:
  - template: 'Jobs/Build.gitlab-ci.yml'

Yep that works fine. See the job history :sunglasses:

Cheers,
Michael

1 Like

Hi Michael,

Thanks for providing the above examples and your step by step testing. I’ve tried this myself and can confirm I’m getting the same output. I’m going to go ahead and use the remote option and will create my own template

Apologies for bumping the thread!

Cheers

John

1 Like