{"id":49535,"date":"2026-11-23T22:06:16","date_gmt":"2026-11-23T22:06:16","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=49535"},"modified":"2026-11-23T22:06:16","modified_gmt":"2026-11-23T22:06:16","slug":"gitlab-complete-details-of-gitlab-ci-yml","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/gitlab-complete-details-of-gitlab-ci-yml\/","title":{"rendered":"Gitlab &#8211; Complete Details of .gitlab-ci.yml"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">GitLab builds every pipeline from one entry-point configuration file, <code>.gitlab-ci.yml<\/code> by default, but that file can pull in any number of other YAML files with the <code>include<\/code> keyword. This page explains the four include methods shown below. It then covers what the original leaves out: what the included files should contain, how GitLab merges and overrides keys, conditional includes, reusable inputs, how to validate the merged result, and the errors you are likely to hit.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default, GitLab only uses <strong>one primary <code>.gitlab-ci.yml<\/code> file<\/strong> located at the root of your repository. However, <strong>you <em>can<\/em> modularize and use multiple CI\/CD YAML files<\/strong> by including them from other locations. Here&#8217;s how it works:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Ways to Use Multiple <code>.gitlab-ci.yml<\/code> Files<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can split your CI\/CD logic into multiple files and include them in the main <code>.gitlab-ci.yml<\/code> using the <code>include<\/code> keyword:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. <strong>Include Local Files<\/strong><\/h4>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">include<\/span>:\n  - local: <span class=\"hljs-string\">'ci-templates\/build.yml'<\/span>\n  - local: <span class=\"hljs-string\">'ci-templates\/deploy.yml'<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\">2. <strong>Include from Other Projects<\/strong><\/h4>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">include<\/span>:\n  - project: <span class=\"hljs-string\">'mygroup\/ci-templates'<\/span>\n    file: <span class=\"hljs-string\">'\/templates\/test.yml'<\/span>\n    ref: main\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\">3. <strong>Include from Remote URLs<\/strong><\/h4>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">include<\/span>:\n  - remote: <span class=\"hljs-string\">'https:\/\/example.com\/gitlab-ci-templates\/security.yml'<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\">4. <strong>Include Templates Provided by GitLab<\/strong><\/h4>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">include<\/span>:\n  - template: <span class=\"hljs-string\">'Security\/SAST.gitlab-ci.yml'<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd01 Merge Strategy<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When GitLab reads your <code>.gitlab-ci.yml<\/code>, it merges the included files <em>before<\/em> executing the pipeline. All the jobs across all included files are considered part of the same pipeline.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udee0\ufe0f Use Case Example<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># .gitlab-ci.yml at the root<\/span>\n<span class=\"hljs-keyword\">include<\/span>:\n  - local: <span class=\"hljs-string\">'ci\/build.yml'<\/span>\n  - local: <span class=\"hljs-string\">'ci\/test.yml'<\/span>\n  - local: <span class=\"hljs-string\">'ci\/deploy.yml'<\/span>\n\nstages:\n  - build\n  - test\n  - deploy\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Each of the <code>build.yml<\/code>, <code>test.yml<\/code>, and <code>deploy.yml<\/code> would define jobs related to their stage.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83e\udde0 Important Notes<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Only <strong>one <code>.gitlab-ci.yml<\/code> at the root<\/strong> is processed directly.<\/li>\n\n\n\n<li>You must <strong>use <code>include<\/code><\/strong> to leverage other YAMLs.<\/li>\n\n\n\n<li>GitLab 12.3+ supports multiple includes.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">The main keywords in a .gitlab-ci.yml file<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before you split a pipeline across files, you need to know which keys are global and which belong to jobs. Global keys apply to the whole pipeline. GitLab treats any other top-level key that is not reserved as a job name.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Keyword<\/th><th>Level<\/th><th>Purpose<\/th><\/tr><\/thead><tbody><tr><td><code>include<\/code><\/td><td>Global<\/td><td>Pulls in other YAML files before the pipeline is created<\/td><\/tr><tr><td><code>stages<\/code><\/td><td>Global<\/td><td>Ordered list of stages. Jobs in the same stage run in parallel<\/td><\/tr><tr><td><code>variables<\/code><\/td><td>Global or job<\/td><td>CI\/CD variables available to jobs<\/td><\/tr><tr><td><code>default<\/code><\/td><td>Global<\/td><td>Default values (for example <code>image<\/code>, <code>before_script<\/code>, <code>tags<\/code>) inherited by every job<\/td><\/tr><tr><td><code>workflow<\/code><\/td><td>Global<\/td><td><code>rules<\/code> that decide whether a pipeline is created at all<\/td><\/tr><tr><td><code>stage<\/code>, <code>script<\/code>, <code>image<\/code><\/td><td>Job<\/td><td>Where the job runs, what it executes and in which container image<\/td><\/tr><tr><td><code>rules<\/code><\/td><td>Job<\/td><td>Conditions that add the job to a pipeline or skip it<\/td><\/tr><tr><td><code>needs<\/code><\/td><td>Job<\/td><td>Lets a job start as soon as specific jobs finish, without waiting for its whole stage<\/td><\/tr><tr><td><code>extends<\/code><\/td><td>Job<\/td><td>Inherits configuration from another job or hidden job (names starting with <code>.<\/code>)<\/td><\/tr><tr><td><code>artifacts<\/code>, <code>cache<\/code><\/td><td>Job<\/td><td>Files passed to later jobs, and files reused between pipelines<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> Hidden jobs have names that start with a dot, such as <code>.docker-base<\/code>, and never run. They exist only to be reused through <code>extends<\/code> or <code>!reference<\/code>, which makes them a good fit for shared template files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A complete multi-file example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The use case example above shows only the root file. Here is a working layout that also shows what goes in the included files, so the pipeline actually has jobs to run.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">repo\/\n\u251c\u2500\u2500 .gitlab-ci.yml\n\u2514\u2500\u2500 ci\/\n    \u251c\u2500\u2500 base.yml\n    \u251c\u2500\u2500 build.yml\n    \u251c\u2500\u2500 test.yml\n    \u2514\u2500\u2500 deploy.yml<\/code><\/span><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># .gitlab-ci.yml<\/span>\nstages:\n  - build\n  - test\n  - deploy\n\n<span class=\"hljs-keyword\">include<\/span>:\n  - local: ci\/base.yml\n  - local: ci\/build.yml\n  - local: ci\/test.yml\n  - local: ci\/deploy.yml<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># ci\/base.yml - shared, non-running configuration<\/span>\n.python-base:\n  image: python:<span class=\"hljs-number\">3.12<\/span>-slim\n  before_script:\n    - pip install -r requirements.txt\n\n<span class=\"hljs-comment\"># ci\/build.yml<\/span>\nbuild-package:\n  stage: build\n  extends: .python-base\n  script:\n    - python -m build\n  artifacts:\n    paths:\n      - dist\/\n\n<span class=\"hljs-comment\"># ci\/test.yml<\/span>\nunit-tests:\n  stage: test\n  extends: .python-base\n  script:\n    - pytest -q\n\n<span class=\"hljs-comment\"># ci\/deploy.yml<\/span>\ndeploy-staging:\n  stage: deploy\n  script:\n    - .\/scripts\/deploy.sh staging\n  environment: staging\n  rules:\n    - <span class=\"hljs-keyword\">if<\/span>: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><code>extends: .python-base<\/code> works across files because GitLab merges all includes into one configuration before it resolves <code>extends<\/code>. Plain YAML anchors (<code>&amp;anchor<\/code> and <code>*anchor<\/code>) do <strong>not<\/strong> work across files, because the YAML parser resolves anchors one file at a time. Use <code>extends<\/code> or <code>!reference<\/code> for anything shared between files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Choosing an include method<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Source<\/th><th>Typical use<\/th><th>Watch out for<\/th><\/tr><\/thead><tbody><tr><td><code>local<\/code><\/td><td>Same repository and same commit<\/td><td>Splitting one project&#039;s pipeline<\/td><td>Paths are relative to the repository root. Wildcards such as <code>ci\/*.yml<\/code> are supported<\/td><\/tr><tr><td><code>project<\/code><\/td><td>Another project on the same GitLab instance<\/td><td>Central templates shared by a team or group<\/td><td>The user running the pipeline needs read access to that project. Pin <code>ref<\/code> to a tag for stability<\/td><\/tr><tr><td><code>remote<\/code><\/td><td>Any HTTP(S) URL<\/td><td>Templates hosted outside GitLab<\/td><td>The URL must be reachable without authentication. Its content can change without warning<\/td><\/tr><tr><td><code>template<\/code><\/td><td>Templates shipped with GitLab<\/td><td>SAST, dependency scanning, Auto DevOps<\/td><td>Template content changes when GitLab is upgraded<\/td><\/tr><tr><td><code>component<\/code><\/td><td>CI\/CD component project, often from the CI\/CD Catalog<\/td><td>Versioned, reusable pipeline building blocks with inputs<\/td><td>Requires a component project with published releases<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><code>include:project<\/code> can load several files from the same project. Pin it to a tag or commit SHA rather than a moving branch:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">include:\n  - project: mygroup\/ci-templates\n    <span class=\"hljs-attr\">ref<\/span>: v1<span class=\"hljs-number\">.4<\/span><span class=\"hljs-number\">.0<\/span>\n    <span class=\"hljs-attr\">file<\/span>:\n      - <span class=\"hljs-regexp\">\/templates\/<\/span>test.yml\n      - <span class=\"hljs-regexp\">\/templates\/<\/span>lint.yml\n  - component: $CI_SERVER_FQDN\/mygroup\/components\/secret-scan@<span class=\"hljs-number\">1.0<\/span><span class=\"hljs-number\">.0<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">How GitLab merges included files<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The merge strategy above says GitLab combines included files before the pipeline runs. The rules that decide which value wins matter just as much:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Included files are merged in the order they are listed. The main <code>.gitlab-ci.yml<\/code> is applied last, so its values override anything included.<\/li>\n\n\n<li>Hashes (maps), such as a job definition or <code>variables<\/code>, are deep-merged key by key.<\/li>\n\n\n<li>Arrays such as <code>script<\/code>, <code>stages<\/code> or <code>rules<\/code> are <strong>replaced<\/strong>, never concatenated.<\/li>\n\n\n<li>Included files can include other files (nested includes), up to depth and total-count limits set by the instance.<\/li>\n<\/ul>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># ci\/test.yml<\/span>\nunit-tests:\n  stage: test\n  image: python:<span class=\"hljs-number\">3.12<\/span>-slim\n  script:\n    - pytest -q\n  variables:\n    LOG_LEVEL: info\n\n<span class=\"hljs-comment\"># .gitlab-ci.yml<\/span>\n<span class=\"hljs-keyword\">include<\/span>:\n  - local: ci\/test.yml\n\nunit-tests:\n  variables:\n    LOG_LEVEL: debug<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The resulting <code>unit-tests<\/code> job keeps the <code>image<\/code>, <code>stage<\/code> and <code>script<\/code> from <code>ci\/test.yml<\/code> but runs with <code>LOG_LEVEL: debug<\/code>. This is a clean way to adjust a shared template for one project. If the main file defined <code>script:<\/code> instead, it would replace the whole script list.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> Define <code>stages<\/code> once, in the main file. If an included file also defines <code>stages<\/code>, the later definition replaces the earlier one entirely. That can leave jobs pointing at a stage that no longer exists.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conditional includes and reusable inputs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An include can have its own <code>rules<\/code>, so GitLab loads a file only when it is relevant. Only <code>if<\/code>, <code>exists<\/code> and <code>changes<\/code> are supported here. You can only use variables that are known when the pipeline is created: predefined, project, group and pipeline variables, but not job variables.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">include<\/span>:\n  - local: ci\/deploy.yml\n    rules:\n      - <span class=\"hljs-keyword\">if<\/span>: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH\n  - local: ci\/docker.yml\n    rules:\n      - exists:\n          - Dockerfile<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">To reuse one template with different values, declare <code>spec:inputs<\/code> in a header section separated by <code>---<\/code>, then reference the inputs with <code>$[[ inputs.name ]]<\/code>. GitLab resolves inputs when it builds the configuration, before any job runs.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># templates\/deploy.yml<\/span>\nspec:\n  inputs:\n    environment:\n      <span class=\"hljs-keyword\">default<\/span>: staging\n---\ndeploy-$&#91;&#91; inputs.environment ]]:\n  stage: deploy\n  script:\n    - .\/scripts\/deploy.sh $&#91;&#91; inputs.environment ]]\n  environment: $&#91;&#91; inputs.environment ]]\n\n<span class=\"hljs-comment\"># .gitlab-ci.yml<\/span>\n<span class=\"hljs-keyword\">include<\/span>:\n  - local: templates\/deploy.yml\n    inputs:\n      environment: production<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Validating the merged configuration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Because GitLab assembles the pipeline from several files, check the final merged result, not just each file on its own.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>In the project, open <strong>Build &gt; Pipeline editor<\/strong>.<\/li>\n\n\n<li>Use the <strong>Validate<\/strong> tab to run a lint check and simulate a pipeline for a branch.<\/li>\n\n\n<li>Open the <strong>Full configuration<\/strong> tab to see every include expanded into one YAML document. This is the quickest way to see which value won a merge.<\/li>\n\n\n<li>From a terminal, the GitLab CLI can lint the current file with <code>glab ci lint<\/code>.<\/li>\n<\/ol>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">glab ci lint<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Common errors and fixes<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Error (paraphrased)<\/th><th>Cause<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td>Local file <code>ci\/build.yml<\/code> does not exist<\/td><td>Wrong path or letter case, or the file is not committed on this branch<\/td><td>Check the path from the repository root and commit the file<\/td><\/tr><tr><td>Project not found or access denied<\/td><td>The pipeline user cannot read the template project, or the path is wrong<\/td><td>Use the full <code>group\/project<\/code> path and grant at least read access<\/td><\/tr><tr><td>Job&#039;s chosen stage does not exist<\/td><td>The job&#039;s <code>stage<\/code> is not in the final <code>stages<\/code> list<\/td><td>Add the stage to <code>stages<\/code> in the main file<\/td><\/tr><tr><td>Remote file could not be fetched<\/td><td>The URL needs authentication, times out, or returns something that is not YAML<\/td><td>Host the file publicly or switch to <code>include:project<\/code><\/td><\/tr><tr><td>Unknown alias or anchor<\/td><td>The file references a YAML anchor defined in another file<\/td><td>Replace anchors with <code>extends<\/code> or <code>!reference<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Corrections to the original<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>The entry file does not have to be at the repository root.<\/strong> The root <code>.gitlab-ci.yml<\/code> is only the default. Under <strong>Settings &gt; CI\/CD &gt; General pipelines<\/strong>, you can set the CI\/CD configuration file to another path or file name, or even to a file in a different project.<\/li>\n\n\n<li><strong>The version note is outdated.<\/strong> The <code>include<\/code> keyword, including multiple and nested includes, has been available in all GitLab tiers for many major releases. Any supported GitLab version supports it, so there is no version to check.<\/li>\n\n\n<li><strong>The merge description is incomplete.<\/strong> GitLab does more than collect jobs: keys in the main file override included keys, maps are deep-merged and arrays are replaced, as described above.<\/li>\n\n\n<li><strong>The use case example has no jobs.<\/strong> It cannot run until the included files define jobs. The complete example above shows the missing files.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best practices<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Keep <code>stages<\/code>, <code>workflow<\/code> and global <code>variables<\/code> in the main file, so the pipeline&#039;s overall layout is visible in one place.<\/li>\n\n\n<li>Pin <code>include:project<\/code> and <code>component<\/code> to a tag or SHA. With a branch reference, template changes reach every project that uses the template immediately.<\/li>\n\n\n<li>Avoid <code>include:remote<\/code> for anything security-sensitive, because you do not control what that URL returns.<\/li>\n\n\n<li>Put reusable logic in hidden jobs and expose options through <code>inputs<\/code> instead of copying jobs.<\/li>\n\n\n<li>Check the <strong>Full configuration<\/strong> view after every template change to confirm which values won the merge.<\/li>\n\n\n<li>To learn the wider pipeline model, see <a href=\"https:\/\/www.devopsschool.com\/blog\/what-is-gitlab-ci-cd-and-use-cases-of-gitlab-ci-cd\/\">What is GitLab CI\/CD and use cases of GitLab CI\/CD?<\/a>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Can a GitLab project have more than one .gitlab-ci.yml file?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Only one file is the pipeline entry point, but it can include any number of other YAML files with <code>include<\/code>. These files can have any name, such as <code>ci\/build.yml<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Does the main .gitlab-ci.yml override included files?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. The main file is merged last, so its keys override included values. Maps are deep-merged, and arrays such as <code>script<\/code> are replaced completely.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why does my YAML anchor not work in an included file?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">YAML anchors are resolved within a single file, before GitLab merges includes. Use <code>extends<\/code> or <code>!reference<\/code> to share configuration across files.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I see the final merged pipeline configuration?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Open Build &gt; Pipeline editor and select the Full configuration tab. It shows every include expanded into a single YAML document.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is the difference between include:project and CI\/CD components?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>include:project<\/code> loads any YAML file from another project. Components are versioned templates that take inputs, are published from a component project and are referenced with <code>include:component<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related tutorials<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/what-is-gitlab-ci-cd-and-use-cases-of-gitlab-ci-cd\/\">What is GitLab CI\/CD and use cases of GitLab CI\/CD?<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/gitlab-top-30-gitlab-pipeline-automation-questions-answers\/\">Gitlab  \u2013 Top 30 GitLab Pipeline Automation FAQ<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/gitlab-for-practical-pipelines-secure-delivery-and-faster-releases\/\">GitLab for Practical Pipelines, Secure Delivery, and Faster Releases<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/gitlab-hierarchy-organization-namespace-group-project\/\">GitLab Hierarchy: Organization, Namespace, Group &amp; Project<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/category\/devops\/gitlab\/\">More GitLab tutorials<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>GitLab builds every pipeline from one entry-point configuration file, .gitlab-ci.yml by default, but that file can pull in any number of other YAML files with the include&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5112],"tags":[26195,5458],"class_list":["post-49535","post","type-post","status-publish","format-standard","hentry","category-gitlab","tag-gitlab-ci-cd","tag-yaml"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/49535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=49535"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/49535\/revisions"}],"predecessor-version":[{"id":80179,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/49535\/revisions\/80179"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=49535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=49535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=49535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}