Search code examples
gitlabyamlgitlab-ci

This GitLab CI configuration is invalid:mapping values are not allowed in this context


I am looking into Gitlab CI templates and have the following .gitlab-ci.yml file:

include:
  - remote: 'https://gitlab.com/gitlab-org/gitlab-foss/-/blob/master/lib/gitlab/ci/templates/Android-Fastlane.gitlab-ci.yml'

stages:
  - build
  - test

build_job:
  stage: build
  script:
    - echo "building application"

test_job:
  stage: test
  script:
    - echo "testing application"

I don't see any indentation errors and I used '' around the url. Still gitlab says:

This GitLab CI configuration is invalid: `https://gitlab.com/gitlab-org/gitlab-foss/-/blob/master/lib/gitlab/ci/templates/Android-Fastlane.gitlab-ci.yml`: (): mapping values are not allowed in this context at line 7 column 17.

What am I missing here? Especially as line 7 is empty and in the template I am trying to include it is a comment


Solution

  • The problem is that you're not using the correct URL. GitLab expects that the response content from the URL is only the YAML file. The URL you are using includes all the HTML for the gitlab page.

    The error might be confusing because it's not actually a problem in your YAML file, exactly. The error actually occurs when trying to load and parse the HTTP response content from the URL you provided as YAML.

    To fix this, you could use the raw link instead.

    Additionally, this template includes jobs that use several stages you'll need in your file as well:

    include:
      - remote: "https://gitlab.com/gitlab-org/gitlab-foss/-/raw/master/lib/gitlab/ci/templates/Android-Fastlane.gitlab-ci.yml"
    
    stages:
      - build
      - test
      - environment
      - internal
      - alpha
      - beta
      - production