Is it possible to use a private GitLab repo as a remote include in GitLab CI? If so, how?

Viewed 1348

Given that I have a private repo with this file:

https://gitlab.com/myuser/snippets/-/raw/main/snippets.yml

.my-snippet:
  before_script:
    - one command here...
    - another thing here...

and that I would like to do this in a .gitlab-ci.yml file in a different private repo:

https://gitlab.com/myuser/coderepo/-/raw/main/.gitlab-ci.yml

include:
  remote: https://gitlab.com/myuser/snippets/-/raw/main/snippets.yml

mycijob:
  extends: .my-snippet
  script:
    - does a thing...
    - probably does something else...

How would a person go about such a thing? I gave deploy tokens a stab, but that didn't appear to work when getting a file's raw content. I get a 503. Is this something that's even possible?

1 Answers

This can be achieved even with a nicer and easier way to handle this.

You can use a special syntax for gitlab, as long as they are on the same instance. you can specify a project and optional ref and the file with this syntax like


include:
  - project: 'myuser/snippets'
    # optional ref, can point to a tag or branch, if not specified the default branch of the target repository is used
    # ref: <git ref> 
    file:
      - 'snippets.yml'

for further information check out the documentation at https://docs.gitlab.com/ee/ci/yaml/includes.html

Related