How do I include CI/CD config from another GitLab project?
Short answer
Add include: with project: set to the full project path and file: set to the YAML file's path from the repository root; add ref: to pin a branch, tag or commit SHA, otherwise GitLab reads the project's HEAD. For a private project, the user running the pipeline needs at least the Reporter role there, or the pipeline fails with a not found or access denied error.
To reuse CI/CD configuration that lives in another project on the same GitLab instance, add an include:project entry with the project’s full path and the file’s path:
include:
- project: 'my-group/my-project'
ref: main
file: '/templates/.gitlab-ci-template.yml'
GitLab reads that file from the other project, merges it into your .gitlab-ci.yml, and builds the pipeline from the result. The file needs a .yml or .yaml extension, and ref is optional: without it, GitLab uses the other project’s HEAD.
Which include type should I use?
include has five forms. They differ in where the file lives and who can read it.
| Type | Use it for | Example | Notes |
|---|---|---|---|
local |
A file in the same repository and branch | local: '/templates/build.yml' |
Supports * and ** wildcards; no submodule paths |
project |
A file in another project on the same instance | project: 'my-group/ci' + file: |
Private projects need the Reporter role |
remote |
A public URL | remote: 'https://example.com/ci.yml' |
No authentication; nested includes run as a public user |
template |
GitLab’s built-in templates | template: Auto-DevOps.gitlab-ci.yml |
Ships with GitLab |
component |
A versioned CI/CD component | component: $CI_SERVER_FQDN/my-org/security-components/secret-detection@1.0 |
Private source projects need the Reporter role |
If you write a bare string, such as include: 'my-config.yml', GitLab treats it as local or remote depending on whether it’s a path or a URL. For sharing between projects on one instance, prefer project over remote: it doesn’t make an HTTP request, and it works with private projects.
How do I include several files or pin a version?
file accepts a list, and you can include from several projects at once:
include:
- project: 'my-group/my-project'
file: '/templates/.gitlab-ci-template.yml'
- project: 'my-group/my-subgroup/my-project-2'
file:
- '/templates/.builds.yml'
- '/templates/.tests.yml'
ref takes a branch name, a tag or a commit SHA. GitLab’s docs list three ways to make it safer, because including another project’s file is, in their words, similar to pulling a third-party dependency:
- A full 40-character commit SHA is the most stable option. A short SHA can be ambiguous.
- A fully qualified ref such as
refs/tags/v1.4.0orrefs/heads/main. A short name can match both a branch and a tag, and when both exist, GitLab takes the file from the tag. - Protected branches and protected tags in the source project, so changes to the shared file go through review.
Also know that editing the shared file triggers no pipelines and no notifications in the projects that include it. Each pipeline takes a snapshot of the included configuration when it starts, so a change only shows up in the next pipeline.
Why does include:project fail with “not found or access denied”?
GitLab shows a not found or access denied error when the user running the pipeline can’t read the included project. Check, in order:
- Permissions. For a private project, the user who runs the pipeline needs at least the Reporter role in the included project. For an internal project, any authenticated user who isn’t external can read it. Public projects need no membership.
- The path.
projectis the full path with every group and subgroup, likemy-group/my-subgroup/my-project-2, not the project name. - The file and ref.
fileis relative to the repository root, and the file has to exist on the ref you named, or on the default HEAD if you didn’t name one.
How do included settings merge with my own?
GitLab merges included files in the order you list them. Nested includes merge first, a later file wins over an earlier one, and your .gitlab-ci.yml is merged last, so its values win. The merge is a deep merge for hashes:
# common.yml in the shared project
variables:
POSTGRES_USER: common_username
POSTGRES_PASSWORD: testing_password
test:
rules:
- when: never
script:
- rake spec
artifacts:
reports:
dotenv: deploy.env
# .gitlab-ci.yml
include: 'common.yml'
variables:
POSTGRES_USER: username
test:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: manual
artifacts:
reports:
junit: rspec.xml
The test job ends up with your rules, the shared script, and both reports, because artifacts is a hash and merges. POSTGRES_USER becomes username, and POSTGRES_PASSWORD stays from the shared file.
Arrays don’t merge. If you set script in your file, it replaces the included script entirely, so you have to repeat the commands you want to keep. A tidier option is a !reference tag that pulls the shared commands into your list; the differences between that, extends and YAML anchors are in How do I reuse GitLab CI config with extends, YAML anchors or !reference?. Anchors won’t help here: they only work inside the file that defines them.
Can I use variables or rules in include?
Yes, within limits. In an include section you can use project, group and instance variables, CI_PROJECT_* predefined variables, trigger, scheduled and manual-run variables, CI_PIPELINE_SOURCE, CI_PIPELINE_TRIGGERED and CI_COMMIT_REF_NAME:
include:
project: '$CI_PROJECT_PATH'
file: '.compliance-gitlab-ci.yml'
Variables from a job or from the top-level variables: section don’t work, because GitLab evaluates includes before jobs. In a dynamic child pipeline’s configuration, no variables work in include.
To include a file only sometimes, add rules with if, exists or changes:
include:
- local: deploys.yml
rules:
- if: $CI_COMMIT_BRANCH == "main"
One trap: rules:exists in a file that came from another project checks for files in that project and ref, not in the project running the pipeline. Set rules:exists:project and rules:exists:ref to change where it looks.
Troubleshooting checklist
-
not found or access denied: give the pipeline user Reporter access, and check the path, file and ref. -
Maximum 150 includes are allowed: too many nested includes, or a loop where two files include each other. -
Local file <file> does not exist!while the file exists: GitLab documents this as an intermittent issue on distributed Gitaly or Praefect setups. Retry the pipeline. -
SSL_connect SYSCALL returned=5withinclude:remote: GitLab couldn’t reach the remote host, often due to rate limits. Don’t host CI files on GitLab Pages; useinclude:project. - A change to the shared file isn’t showing: it applies from the next pipeline, and only if you aren’t pinned to an older ref or SHA.
- Jobs lost commands after an override: your
scriptreplaced the included array.
When a shared template breaks pipelines across many projects at once, you usually find out from a failure. MergeBell can send a push when your merge request’s pipeline fails, and its file browser and raw viewer let you read the shared template on your phone to see which change caused it.
Frequently asked questions
How do I include a file from another GitLab project?
Use include: - project: 'my-group/my-project' with file: '/templates/.gitlab-ci-template.yml'. file can also be a list of paths, each relative to the repository root and ending in .yml or .yaml. Add ref: to choose a branch, tag or commit SHA.
Why do I get "not found or access denied" for include:project?
The user running the pipeline can't read the other project. For a private project they need at least the Reporter role; for an internal project any authenticated non-external user is enough; public projects need no membership. Also check the project path and that the file exists on the ref you included.
Which version of the included file does my pipeline use?
The one on include:ref, or the project's HEAD if you leave ref out. GitLab evaluates includes when the pipeline starts and stores that snapshot, so later changes to the file only apply to the next pipeline. Changing the file doesn't trigger pipelines in the projects that include it.
Can I use variables in include?
Yes, with limits: project, group and instance variables, CI_PROJECT_* predefined variables, trigger, schedule and manual-run variables, CI_PIPELINE_SOURCE, CI_PIPELINE_TRIGGERED and CI_COMMIT_REF_NAME. Variables defined in jobs or in the global variables section don't work, because includes are evaluated first.
Can I add one command to an included job's script?
Not by merging. Arrays like script aren't merged, so a script in your .gitlab-ci.yml replaces the included one. Repeat the commands you want to keep, or use a !reference tag to pull the included script into yours.
Sources
- GitLab docs — CI/CD YAML syntax reference: include
- GitLab docs — Use CI/CD configuration from other files
- GitLab docs — Optimize GitLab CI/CD configuration files
Checked against these pages on 21 November 2026. GitLab changes quickly — if something here no longer matches, tell us and we will fix it.
Do this from your phone with MergeBell
Free for the whole review loop: the To-Do inbox, diffs and line comments, approve and merge, pipelines with retry, and push alerts for your To-Dos. Works with gitlab.com and self-managed GitLab 16.0+.
Get MergeBell for iPhoneGet MergeBell for Android
On the App Store for iOS 26 or later and on Google Play for Android 12 or later. An independent app, not affiliated with GitLab Inc.