Allow CI_APPLICATION_REPOSITORY/TAG to be customized in Auto DevOps

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

  • Close this issue

Problem to solve

For building Docker images in a project, GitLab CI provides the predefined variable CI_REGISTRY_IMAGE that returns the base image name for images stored the Container Registry tied to the project. This can be be used in conjunction with CI_COMMIT_REF_NAME or CI_COMMIT_REF_SLUG for the image tag. The Docker.gitlab-ci.yml template demonstrates this in its build job script.

script:
  - docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" .
  - docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"

GitLab Auto DevOps declares two local variables in its before_script for the image name and tag.

export CI_APPLICATION_REPOSITORY=$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG
export CI_APPLICATION_TAG=$CI_COMMIT_SHA

CI_APPLICATION_REPOSITORY is used to define the image name, and CI_APPLICATION_TAG for the image tag. However, they are declared via export commands in the before_script instead of in a variables block and without checking for existing values in those variables. This makes them extremely difficult to override without re-declaring the entire auto_devops before_script.

Further details

GitLab AutoDevops names and tags Docker images a bit differently than “normal”. The branch or tag name is placed as part of the image name, instead of used as the image tag. Then, the image is tagged with the Git commit SHA. Here is a hypothetical example.

“Normal”:    http://registry.gitlab.com/group/project:branch
Auto DevOps: http://registry.gitlab.com/group/project/branch:6a4e6a6

Proposal

For my build process, I prefer to have images named in the more traditional way. I also use sub-levels to tag images from build stages in multi-stage Dockerfiles. For this to work in Auto Devops, I need a way to override CI_APPLICATION_REPOSITORY and CI_APPLICATION_TAG.

I propose that GitLab Auto Devops declare CI_APPLICATION_REPOSITORY and CI_APPLICATION_TAG as YAML-defined global variables, instead of exports in the before_script.

variables:
  # AUTO_DEVOPS_DOMAIN is the application deployment domain and should be set as a variable at the group or project level.
  # AUTO_DEVOPS_DOMAIN: domain.example.com

  CI_APPLICATION_REPOSITORY: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG
  CI_APPLICATION_TAG: $CI_COMMIT_SHA

  POSTGRES_USER: user
  POSTGRES_PASSWORD: testing-password
  POSTGRES_ENABLED: "true"
  POSTGRES_DB: $CI_ENVIRONMENT_SLUG

  KUBERNETES_VERSION: 1.8.6
  HELM_VERSION: 2.11.0

  DOCKER_DRIVER: overlay2

This way, the variables can be easily overwritten following the priority of variables.

What does success look like, and how can we measure that?

I should be able to define other values for CI_APPLICATION_REPOSITORY and CI_APPLICATION_TAG, perhaps in a .gitlab-ci.yml file in my project that includes Auto DevOps.

Links / references

  • Relates to gitlab-ce#49395
  • Duplicate of gitlab-ci-yml#50.
Edited Aug 26, 2025 by 🤖 GitLab Bot 🤖
Assignee Loading
Time tracking Loading