Add predefined CI variables to GitLab for container registry, pipelines, project name, etc.

This commit is contained in:
Kamil Trzcinski 2016-06-21 13:55:33 +02:00
parent 44b8b77e02
commit 0aedeb5637
3 changed files with 67 additions and 28 deletions

View file

@ -29,6 +29,7 @@ v 8.9.0 (unreleased)
- Reduce number of fog gem dependencies - Reduce number of fog gem dependencies
- Add number of merge requests for a given milestone to the milestones view. - Add number of merge requests for a given milestone to the milestones view.
- Implement a fair usage of shared runners - Implement a fair usage of shared runners
- Add predefined CI variables to GitLab for container registry, pipelines, project name, etc.
- Remove project notification settings associated with deleted projects - Remove project notification settings associated with deleted projects
- Fix 404 page when viewing TODOs that contain milestones or labels in different projects - Fix 404 page when viewing TODOs that contain milestones or labels in different projects
- Add a metric for the number of new Redis connections created by a transaction - Add a metric for the number of new Redis connections created by a transaction

View file

@ -431,10 +431,34 @@ module Ci
def predefined_variables def predefined_variables
variables = [] variables = []
variables << { key: :CI_BUILD_TAG, value: ref, public: true } if tag? variables << { key: 'CI', value: 'true', public: true }
variables << { key: :CI_BUILD_NAME, value: name, public: true } variables << { key: 'GITLAB_CI', value: 'true', public: true }
variables << { key: :CI_BUILD_STAGE, value: stage, public: true }
variables << { key: :CI_BUILD_TRIGGERED, value: 'true', public: true } if trigger_request variables << { key: 'CI_BUILD_ID', value: id, public: true }
variables << { key: 'CI_BUILD_TOKEN', value: token, public: false }
variables << { key: 'CI_BUILD_REF', value: sha, public: true }
variables << { key: 'CI_BUILD_BEFORE_SHA', value: before_sha, public: true }
variables << { key: 'CI_BUILD_REF_NAME', value: ref, public: true }
variables << { key: 'CI_BUILD_TAG', value: ref, public: true } if tag?
variables << { key: 'CI_BUILD_NAME', value: name, public: true }
variables << { key: 'CI_BUILD_STAGE', value: stage, public: true }
variables << { key: 'CI_BUILD_TRIGGERED', value: 'true', public: true } if trigger_request
variables << { key: 'CI_PIPELINE_ID', value: pipeline.id, public: true }
variables << { key: 'CI_PROJECT_ID', value: project_id, public: true }
variables << { key: 'CI_PROJECT_NAME', value: project.path, public: true }
variables << { key: 'CI_PROJECT_PATH', value: project.path_with_namespace, public: true }
variables << { key: 'CI_PROJECT_NAMESPACE', value: project.namespace.path, public: true }
variables << { key: 'CI_PROJECT_URL', value: project.web_url, public: true }
variables << { key: 'CI_REGISTRY', value: Gitlab.config.registry.host_port, public: true } if Gitlab.config.registry.enabled
variables << { key: 'CI_REGISTRY_IMAGE', value: project.container_registry_repository_url, public: true } if project.container_registry_repository_url
variables << { key: 'CI_SERVER_NAME', value: 'GitLab', public: true }
variables << { key: 'CI_SERVER_VERSION', value: Gitlab::VERSION, public: true }
variables << { key: 'CI_SERVER_REVISION', value: Gitlab::REVISION, public: true }
variables << { key: 'CI_SERVER_URL', value: Gitlab::REVISION, public: true }
variables variables
end end
end end

View file

@ -18,25 +18,32 @@ The `API_TOKEN` will take the Secure Variable value: `SECURE`.
### Predefined variables (Environment Variables) ### Predefined variables (Environment Variables)
| Variable | Runner | Description | | Variable | GitLab | Runner | Description |
|-------------------------|-----|--------| |-------------------------|--------|--------|-------------|
| **CI** | 0.4 | Mark that build is executed in CI environment | | **CI** | all | 0.4 | Mark that build is executed in CI environment |
| **GITLAB_CI** | all | Mark that build is executed in GitLab CI environment | | **GITLAB_CI** | all | all | Mark that build is executed in GitLab CI environment |
| **CI_SERVER** | all | Mark that build is executed in CI environment | | **CI_SERVER** | all | all | Mark that build is executed in CI environment |
| **CI_SERVER_NAME** | all | CI server that is used to coordinate builds | | **CI_SERVER_NAME** | all | all | The name of CI server that is used to coordinate builds |
| **CI_SERVER_VERSION** | all | Not yet defined | | **CI_SERVER_VERSION** | all | all | GitLab version that is used to schedule builds |
| **CI_SERVER_REVISION** | all | Not yet defined | | **CI_SERVER_REVISION** | all | all | GitLab revision that is used to schedule builds |
| **CI_BUILD_REF** | all | The commit revision for which project is built | | **CI_BUILD_ID** | all | all | The unique id of the current build that GitLab CI uses internally |
| **CI_BUILD_TAG** | 0.5 | The commit tag name. Present only when building tags. | | **CI_BUILD_REF** | all | all | The commit revision for which project is built |
| **CI_BUILD_NAME** | 0.5 | The name of the build as defined in `.gitlab-ci.yml` | | **CI_BUILD_TAG** | all | 0.5 | The commit tag name. Present only when building tags. |
| **CI_BUILD_STAGE** | 0.5 | The name of the stage as defined in `.gitlab-ci.yml` | | **CI_BUILD_NAME** | all | 0.5 | The name of the build as defined in `.gitlab-ci.yml` |
| **CI_BUILD_REF_NAME** | all | The branch or tag name for which project is built | | **CI_BUILD_STAGE** | all | 0.5 | The name of the stage as defined in `.gitlab-ci.yml` |
| **CI_BUILD_ID** | all | The unique id of the current build that GitLab CI uses internally | | **CI_BUILD_REF_NAME** | all | all | The branch or tag name for which project is built |
| **CI_BUILD_REPO** | all | The URL to clone the Git repository | | **CI_BUILD_REPO** | all | all | The URL to clone the Git repository |
| **CI_BUILD_TRIGGERED** | 0.5 | The flag to indicate that build was [triggered] | | **CI_BUILD_TRIGGERED** | all | 0.5 | The flag to indicate that build was [triggered] |
| **CI_BUILD_TOKEN** | 1.2 | Token used for authenticating with the GitLab Container Registry | | **CI_BUILD_TOKEN** | all | 1.2 | Token used for authenticating with the GitLab Container Registry |
| **CI_PROJECT_ID** | all | The unique id of the current project that GitLab CI uses internally | | **CI_PIPELINE_ID** | 8.9 | 0.5 | The unique id of the current pipeline that GitLab CI uses internally |
| **CI_PROJECT_DIR** | all | The full path where the repository is cloned and where the build is ran | | **CI_PROJECT_ID** | all | all | The unique id of the current project that GitLab CI uses internally |
| **CI_PROJECT_NAME** | 8.9 | 0.5 | The project name that is currently build |
| **CI_PROJECT_NAMESPACE**| 8.9 | 0.5 | The project namespace that is currently build |
| **CI_PROJECT_PATH** | 8.9 | 0.5 | The namespace with project name |
| **CI_PROJECT_URL** | 8.9 | 0.5 | The HTTP address to access project |
| **CI_PROJECT_DIR** | all | all | The full path where the repository is cloned and where the build is ran |
| **CI_REGISTRY** | 8.9 | 0.5 | If the Container Registry is enabled it returns address of GitLab's Container Registry |
| **CI_REGISTRY_IMAGE** | 8.9 | 0.5 | If the Container Registry is for project it returns the address of registry tied to specific project |
**Some of the variables are only available when using runner with at least defined version.** **Some of the variables are only available when using runner with at least defined version.**
@ -46,18 +53,25 @@ Example values:
export CI_BUILD_ID="50" export CI_BUILD_ID="50"
export CI_BUILD_REF="1ecfd275763eff1d6b4844ea3168962458c9f27a" export CI_BUILD_REF="1ecfd275763eff1d6b4844ea3168962458c9f27a"
export CI_BUILD_REF_NAME="master" export CI_BUILD_REF_NAME="master"
export CI_BUILD_REPO="https://gitlab.com/gitlab-org/gitlab-ce.git" export CI_BUILD_REPO="https://gitab-ci-token:abcde-1234ABCD5678ef@gitlab.com/gitlab-org/gitlab-ce.git"
export CI_BUILD_TAG="1.0.0" export CI_BUILD_TAG="1.0.0"
export CI_BUILD_NAME="spec:other" export CI_BUILD_NAME="spec:other"
export CI_BUILD_STAGE="test" export CI_BUILD_STAGE="test"
export CI_BUILD_TRIGGERED="true" export CI_BUILD_TRIGGERED="true"
export CI_BUILD_TOKEN="abcde-1234ABCD5678ef" export CI_BUILD_TOKEN="abcde-1234ABCD5678ef"
export CI_PROJECT_DIR="/builds/gitlab-org/gitlab-ce" export CI_PIPELINE_ID="1000"
export CI_PROJECT_ID="34" export CI_PROJECT_ID="34"
export CI_PROJECT_DIR="/builds/gitlab-org/gitlab-ce"
export CI_PROJECT_NAME="gitlab-ce"
export CI_PROJECT_NAMESPACE="gitlab-org"
export CI_PROJECT_PATH="gitlab-org/gitlab-ce"
export CI_PROJECT_URL="https://gitlab.com/gitlab-org/gitlab-ce.git"
export CI_REGISTRY="registry.gitlab.com"
export CI_REGISTRY_IMAGE="registry.gitlab.com/gitlab-org/gitlab-ce"
export CI_SERVER="yes" export CI_SERVER="yes"
export CI_SERVER_NAME="GitLab CI" export CI_SERVER_NAME="GitLab"
export CI_SERVER_REVISION="" export CI_SERVER_REVISION="8.9.0"
export CI_SERVER_VERSION="" export CI_SERVER_VERSION="70606bf"
``` ```
### YAML-defined variables ### YAML-defined variables