Include and extends in gitlab.com not working

I’m using the gitlab-ci.yml configuration bellow and I’m facing the validation problem build-push-docker: unknown keys in extends (.build-push-docker) but in the template included there is the .build-push-docker task.

includes: https://gitlab.com/kugelbit/infra/infra-gitlab-ci/-/raw/main/template-gitlab-ci.yml
variables:
  GRADLE_OPTS: "-Dorg.gradle.daemon=false"
  PROJECT_NAME: pipeline-test
  LATEST_VERSION: latest
stages:
  - build
  - quality-check
  - build-push-docker
  - deploy
cache:
  paths:
    - build
    - .gradle
before_script:
  - export GRADLE_USER_HOME=`pwd`/.gradle
  - chmod +x ./gradlew

build:
  image: openjdk:11-slim
  stage: build
  script:
    - ./gradlew build
  artifacts:
    paths:
      - build/libs/*.jar
    expire_in: 1 week
build-push-docker:
  variables:
    IMAGE_NAME: $PROJECT_NAME
    IMAGE_VERSION: $LATEST_VERSION
  extends: .build-push-docker
  only:
    - master
build-push-docker-prod:
  variables:
    IMAGE_NAME: $PROJECT_NAME
    IMAGE_VERSION: $CI_COMMIT_TAG
  extends: .build-push-docker
  only:
    - tags

Included file:

variables:
  DOCKER_TLS_CERTDIR: ""
  DOCKER_HOST: tcp://docker:2375

.build-push-docker:
  stage: build-push-docker
  image: docker:latest
  services:
  - docker:19.03.13-dind
  before_script: []
  variables:
    IMAGE_NAME: ""
    IMAGE_VERSION: ""
    DOCKERFILE_PATH: .
  script:
    - echo "IMAGEM -> "${REGISTRY_URL}/${IMAGE_NAME}:${IMAGE_VERSION}
    - echo "DOCKERFILE PATH -> "$DOCKERFILE_PATH
    - docker build -t ${REGISTRY_URL}/${IMAGE_NAME}:${IMAGE_VERSION} $DOCKERFILE_PATH
    - docker tag ${REGISTRY_URL}/${IMAGE_NAME}:${IMAGE_VERSION} ${REGISTRY_URL}/${IMAGE_NAME}:${IMAGE_VERSION}
    - docker login -u $REGISTRY_USER -p $REGISTRY_PASSWORD $REGISTRY_URL
    - docker push ${REGISTRY_URL}/${IMAGE_NAME}:${IMAGE_VERSION}

Hi @gcsilva
Try to use

extends: ['.build-push-docker']

or

extends:
  - .build-push-docker

Nevermind my previous answer. I just noticed you are not including the file properly.

include:
  - remote: 'https://gitlab.com/kugelbit/infra/infra-gitlab-ci/-/raw/main/template-gitlab-ci.yml'

As you can see in the docs, the target file must be publicly accessible, there is no authentication for includes.

1 Like

Thanks for the answer, this solves the problem