CI_APPLICATION_TAG 在 GItLab 中定义在哪里?

Where is CI_APPLICATION_TAG define in GItLab?

我是 GitLab Auto DevOps 的新手。

我遇到了一些环境变量,它们是“CI_APPLICATION_TAG”、“CI_APPLICATION_REPOSITORY”、“CI_COMMIT_REF_SLUG”。

I can't find where their definitions are. Is there anyone can help me?

您可以在 gitlab-org/gitlab-ci-yml issue 50

中看到它们的实际效果

The Docker image naming strategy in Auto DevOps is defined via the CI_APPLICATION_REPOSITORY and CI_APPLICATION_TAG variables near the start of the auto_devops before_script.
The format differs from the way I name and tag images, but the inline export statements make it difficult to customize since the script itself has to be modified.

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

此外,gitlab-org/gitlab-ce issue 53129

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.

- 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

来自https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml

的片段
      if [[ -z "$CI_COMMIT_TAG" ]]; then
        export CI_APPLICATION_REPOSITORY=${CI_APPLICATION_REPOSITORY:-$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG}
        export CI_APPLICATION_TAG=${CI_APPLICATION_TAG:-$CI_COMMIT_SHA}
      else
        export CI_APPLICATION_REPOSITORY=${CI_APPLICATION_REPOSITORY:-$CI_REGISTRY_IMAGE}
        export CI_APPLICATION_TAG=${CI_APPLICATION_TAG:-$CI_COMMIT_TAG}
      fi