README.md 34,2 КБ
Newer Older
Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
1
2
3
4
---
table_display_block: true
---

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
5
# GitLab CI/CD Variables
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
6

Evan Read's avatar
Evan Read включено в состав коммита
7
8
9
10
11
When receiving a job from GitLab CI, the [Runner](https://docs.gitlab.com/runner/) prepares the build environment.
It starts by setting a list of:

- [Predefined environment variables](#predefined-environment-variables).
- Other variables.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
12

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
13
## Priority of variables
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
14

Evan Read's avatar
Evan Read включено в состав коммита
15
16
17
18
19
20
21
22
23
24
25
Variables of different types can take precedence over other variables, depending on where they are defined.

The order of precedence for variables is (from highest to lowest):

1. [Trigger variables](../triggers/README.md#pass-job-variables-to-a-trigger) or [scheduled pipeline variables](../../user/project/pipelines/schedules.md#making-use-of-scheduled-pipeline-variables).
1. Project-level [variables](#variables) or [protected variables](#protected-variables).
1. Group-level [variables](#variables) or [protected variables](#protected-variables).
1. YAML-defined [job-level variables](../yaml/README.md#variables).
1. YAML-defined [global variables](../yaml/README.md#variables).
1. [Deployment variables](#deployment-variables).
1. [Predefined environment variables](#predefined-environment-variables).
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
26

Evan Read's avatar
Evan Read включено в состав коммита
27
For example, you define:
Douwe Maan's avatar
Douwe Maan включено в состав коммита
28

Evan Read's avatar
Evan Read включено в состав коммита
29
30
31
32
33
- `API_TOKEN=secure` as a project variable.
- `API_TOKEN=yaml` in your `.gitlab-ci.yml`.

`API_TOKEN` will take the value `secure` as the project variables take precedence over those defined
in `.gitlab-ci.yml`.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
34

Tomasz Maczukin's avatar
Tomasz Maczukin включено в состав коммита
35
36
37
38
39
40
## Unsupported variables

There are cases where some variables cannot be used in the context of a
`.gitlab-ci.yml` definition (for example under `script`). Read more
about which variables are [not supported](where_variables_can_be_used.md).

Evan Read's avatar
Evan Read включено в состав коммита
41
## Predefined environment variables
Douwe Maan's avatar
Douwe Maan включено в состав коммита
42

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
43
Some of the predefined environment variables are available only if a minimum
Evan Read's avatar
Evan Read включено в состав коммита
44
version of [GitLab Runner](https://docs.gitlab.com/runner/) is used. Consult the table below to find the
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
45
version of Runner required.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
46

Evan Read's avatar
Evan Read включено в состав коммита
47
NOTE: **Note:**
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
48
49
50
51
52
Starting with GitLab 9.0, we have deprecated some variables. Read the
[9.0 Renaming](#9-0-renaming) section to find out their replacements. **You are
strongly advised to use the new variables as we will remove the old ones in
future GitLab releases.**

Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
53
54
55
| Variable                                  | GitLab | Runner | Description |
|-------------------------------------------|--------|--------|-------------|
| **ARTIFACT_DOWNLOAD_ATTEMPTS**            | 8.15   | 1.9    | Number of attempts to download artifacts running a job |
James Fargher's avatar
James Fargher включено в состав коммита
56
57
| **CHAT_INPUT**                            | 10.6   | all    | Additional arguments passed in the [ChatOps](../chatops/README.md) command |
| **CHAT_CHANNEL**                          | 10.6   | all    | Source chat channel which triggered the [ChatOps](../chatops/README.md) command |
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
58
| **CI**                                    | all    | 0.4    | Mark that job is executed in CI environment |
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
59
60
61
| **CI_COMMIT_BEFORE_SHA**                  | 11.2   | all    | The previous latest commit present on a branch before a push request. |
| **CI_COMMIT_DESCRIPTION**                 | 10.8   | all    | The description of the commit: the message without first line, if the title is shorter than 100 characters; full message in other case. |
| **CI_COMMIT_MESSAGE**                     | 10.8   | all    | The full commit message. |
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
62
63
64
| **CI_COMMIT_REF_NAME**                    | 9.0    | all    | The branch or tag name for which project is built |
| **CI_COMMIT_REF_SLUG**                    | 9.0    | all    | `$CI_COMMIT_REF_NAME` lowercased, shortened to 63 bytes, and with everything except `0-9` and `a-z` replaced with `-`. No leading / trailing `-`. Use in URLs, host names and domain names. |
| **CI_COMMIT_SHA**                         | 9.0    | all    | The commit revision for which project is built |
Jason Lenny's avatar
Jason Lenny включено в состав коммита
65
| **CI_COMMIT_SHORT_SHA**                   | 11.7   | all    | The first eight characters of `CI_COMMIT_SHA` |
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
66
67
68
69
| **CI_COMMIT_TAG**                         | 9.0    | 0.5    | The commit tag name. Present only when building tags. |
| **CI_COMMIT_TITLE**                       | 10.8   | all    | The title of the commit - the full first line of the message |
| **CI_CONFIG_PATH**                        | 9.4    | 0.5    | The path to CI config file. Defaults to `.gitlab-ci.yml` |
| **CI_DEBUG_TRACE**                        | all    | 1.7    | Whether [debug tracing](#debug-tracing) is enabled |
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
70
| **CI_DEPLOY_PASSWORD**                    | 10.8   | all    | Authentication password of the [GitLab Deploy Token][gitlab-deploy-token], only present if the Project has one related.|
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
71
| **CI_DEPLOY_USER**                        | 10.8   | all    | Authentication username of the [GitLab Deploy Token][gitlab-deploy-token], only present if the Project has one related.|
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
72
| **CI_DISPOSABLE_ENVIRONMENT**             | all    | 10.1   | Marks that the job is executed in a disposable environment (something that is created only for this job and disposed of/destroyed after the execution - all executors except `shell` and `ssh`). If the environment is disposable, it is set to true, otherwise it is not defined at all. |
Evan Read's avatar
Evan Read включено в состав коммита
73
| **CI_ENVIRONMENT_NAME**                   | 8.15   | all    | The name of the environment for this job. Only present if [`environment:name`](../yaml/README.md#environmentname) is set. |
Oliver Bristow's avatar
Oliver Bristow включено в состав коммита
74
75
| **CI_ENVIRONMENT_SLUG**                   | 8.15   | all    | A simplified version of the environment name, suitable for inclusion in DNS, URLs, Kubernetes labels, etc. Only present if [`environment:name`](../yaml/README.md#environmentname) is set. |
| **CI_ENVIRONMENT_URL**                    | 9.3    | all    | The URL of the environment for this job. Only present if [`environment:url`](../yaml/README.md#environmenturl) is set. |
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
76
77
78
79
80
| **CI_JOB_ID**                             | 9.0    | all    | The unique id of the current job that GitLab CI uses internally |
| **CI_JOB_MANUAL**                         | 8.12   | all    | The flag to indicate that job was manually started |
| **CI_JOB_NAME**                           | 9.0    | 0.5    | The name of the job as defined in `.gitlab-ci.yml` |
| **CI_JOB_STAGE**                          | 9.0    | 0.5    | The name of the stage as defined in `.gitlab-ci.yml` |
| **CI_JOB_TOKEN**                          | 9.0    | 1.2    | Token used for authenticating with the [GitLab Container Registry][registry] and downloading [dependent repositories][dependent-repositories] |
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
81
| **CI_JOB_URL**                            | 11.1   | 0.5    | Job details URL |
Hiroyuki Sato's avatar
Hiroyuki Sato включено в состав коммита
82
83
84
85
86
87
88
89
90
91
92
93
94
95
| **CI_MERGE_REQUEST_ID**                   | 11.6   | all    | The ID of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) |
| **CI_MERGE_REQUEST_IID**                  | 11.6   | all    | The IID of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) |
| **CI_MERGE_REQUEST_PROJECT_ID**           | 11.6   | all    | The ID of the project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) |
| **CI_MERGE_REQUEST_PROJECT_PATH**         | 11.6   | all    | The path of the project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) (e.g. `namespace/awesome-project`) |
| **CI_MERGE_REQUEST_PROJECT_URL**          | 11.6   | all    | The URL of the project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) (e.g. `http://192.168.10.15:3000/namespace/awesome-project`) |
| **CI_MERGE_REQUEST_REF_PATH**             | 11.6   | all    | The ref path of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md). (e.g. `refs/merge-requests/1/head`) |
| **CI_MERGE_REQUEST_SOURCE_BRANCH_NAME**   | 11.6   | all    | The source branch name of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) |
| **CI_MERGE_REQUEST_SOURCE_BRANCH_SHA**    | 11.9   | all    | The HEAD sha of the source branch of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) |
| **CI_MERGE_REQUEST_SOURCE_PROJECT_ID**    | 11.6   | all    | The ID of the source project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) |
| **CI_MERGE_REQUEST_SOURCE_PROJECT_PATH**  | 11.6   | all    | The path of the source project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) |
| **CI_MERGE_REQUEST_SOURCE_PROJECT_URL**   | 11.6   | all    | The URL of the source project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) |
| **CI_MERGE_REQUEST_TARGET_BRANCH_NAME**   | 11.6   | all    | The target branch name of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) |
| **CI_MERGE_REQUEST_TARGET_BRANCH_SHA**    | 11.9   | all    | The HEAD sha of the target branch of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) |
| **CI_MERGE_REQUEST_TITLE**                | 11.9   | all    | The title of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) |
Evan Read's avatar
Evan Read включено в состав коммита
96
| **CI_MERGE_REQUEST_ASSIGNEES**            | 11.9   | all    | Comma-separated list of usernames of assignees for the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md). [Multiple assignees for merge requests](https://gitlab.com/gitlab-org/gitlab-ee/issues/2004) is scheduled for a future release |
Hiroyuki Sato's avatar
Hiroyuki Sato включено в состав коммита
97
98
| **CI_MERGE_REQUEST_MILESTONE**            | 11.9   | all    | The milestone title of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) |
| **CI_MERGE_REQUEST_LABELS**               | 11.9   | all    | Comma-separated label names of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) |
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
99
100
| **CI_NODE_INDEX**                         | 11.5   | all    | Index of the job in the job set. If the job is not parallelized, this variable is not set. |
| **CI_NODE_TOTAL**                         | 11.5   | all    | Total number of instances of this job running in parallel. If the job is not parallelized, this variable is set to `1`. |
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
101
| **CI_API_V4_URL**                         | 11.7   | all    | The GitLab API v4 root URL |
Adrian Moisey's avatar
Adrian Moisey включено в состав коммита
102
103
| **CI_PAGES_DOMAIN**                       | 11.8   | all    | The configured domain that hosts GitLab Pages. |
| **CI_PAGES_URL**                          | 11.8   | all    | URL to GitLab Pages-built pages. Always belongs to a subdomain of `CI_PAGES_DOMAIN`. |
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
104
| **CI_PIPELINE_ID**                        | 8.10   | all    | The unique id of the current pipeline that GitLab CI uses internally |
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
105
106
| **CI_PIPELINE_IID**                       | 11.0   | all    | The unique id of the current pipeline scoped to project |
| **CI_PIPELINE_SOURCE**                    | 10.0   | all    | Indicates how the pipeline was triggered. Possible options are: `push`, `web`, `trigger`, `schedule`, `api`, and `pipeline`. For pipelines created before GitLab 9.5, this will show as `unknown` |
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
107
108
| **CI_PIPELINE_TRIGGERED**                 | all    | all    | The flag to indicate that job was [triggered] |
| **CI_PIPELINE_URL**                       | 11.1   | 0.5    | Pipeline details URL |
Craig Davidson's avatar
Craig Davidson включено в состав коммита
109
| **CI_PROJECT_DIR**                        | all    | all    | The full path where the repository is cloned and where the job is run. If the GitLab Runner `builds_dir` parameter is set, this variable is set relative to the value of `builds_dir`. For more information, see [Advanced configuration](https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-section) for GitLab Runner. |
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
110
111
112
113
114
| **CI_PROJECT_ID**                         | all    | all    | The unique id of the current project that GitLab CI uses internally |
| **CI_PROJECT_NAME**                       | 8.10   | 0.5    | The project name that is currently being built (actually it is project folder name) |
| **CI_PROJECT_NAMESPACE**                  | 8.10   | 0.5    | The project namespace (username or groupname) that is currently being built |
| **CI_PROJECT_PATH**                       | 8.10   | 0.5    | The namespace with project name |
| **CI_PROJECT_PATH_SLUG**                  | 9.3    | all    | `$CI_PROJECT_PATH` lowercased and with everything except `0-9` and `a-z` replaced with `-`. Use in URLs and domain names. |
Mark Fletcher's avatar
Mark Fletcher включено в состав коммита
115
| **CI_PROJECT_URL**                        | 8.10   | 0.5    | The HTTP(S) address to access project |
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
116
117
118
119
120
| **CI_PROJECT_VISIBILITY**                 | 10.3   | all    | The project visibility (internal, private, public) |
| **CI_REGISTRY**                           | 8.10   | 0.5    | If the Container Registry is enabled it returns the address of GitLab's Container Registry |
| **CI_REGISTRY_IMAGE**                     | 8.10   | 0.5    | If the Container Registry is enabled for the project it returns the address of the registry tied to the specific project |
| **CI_REGISTRY_PASSWORD**                  | 9.0    | all    | The password to use to push containers to the GitLab Container Registry |
| **CI_REGISTRY_USER**                      | 9.0    | all    | The username to use to push containers to the GitLab Container Registry |
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
121
122
123
124
125
126
127
| **CI_REPOSITORY_URL**                     | 9.0    | all    | The URL to clone the Git repository |
| **CI_RUNNER_DESCRIPTION**                 | 8.10   | 0.5    | The description of the runner as saved in GitLab |
| **CI_RUNNER_EXECUTABLE_ARCH**             | all    | 10.6   | The OS/architecture of the GitLab Runner executable (note that this is not necessarily the same as the environment of the executor) |
| **CI_RUNNER_ID**                          | 8.10   | 0.5    | The unique id of runner being used |
| **CI_RUNNER_REVISION**                    | all    | 10.6   | GitLab Runner revision that is executing the current job |
| **CI_RUNNER_TAGS**                        | 8.10   | 0.5    | The defined runner tags |
| **CI_RUNNER_VERSION**                     | all    | 10.6   | GitLab Runner version that is executing the current job |
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
| **CI_SERVER**                             | all    | all    | Mark that job is executed in CI environment |
| **CI_SERVER_NAME**                        | all    | all    | The name of CI server that is used to coordinate jobs |
| **CI_SERVER_REVISION**                    | all    | all    | GitLab revision that is used to schedule jobs |
| **CI_SERVER_VERSION**                     | all    | all    | GitLab version that is used to schedule jobs |
| **CI_SERVER_VERSION_MAJOR**               | 11.4   | all    | GitLab version major component |
| **CI_SERVER_VERSION_MINOR**               | 11.4   | all    | GitLab version minor component |
| **CI_SERVER_VERSION_PATCH**               | 11.4   | all    | GitLab version patch component |
| **CI_SHARED_ENVIRONMENT**                 | all    | 10.1   | Marks that the job is executed in a shared environment (something that is persisted across CI invocations like `shell` or `ssh` executor). If the environment is shared, it is set to true, otherwise it is not defined at all. |
| **GET_SOURCES_ATTEMPTS**                  | 8.15   | 1.9    | Number of attempts to fetch sources running a job |
| **GITLAB_CI**                             | all    | all    | Mark that job is executed in GitLab CI environment |
| **GITLAB_USER_EMAIL**                     | 8.12   | all    | The email of the user who started the job |
| **GITLAB_USER_ID**                        | 8.12   | all    | The id of the user who started the job |
| **GITLAB_USER_LOGIN**                     | 10.0   | all    | The login username of the user who started the job |
| **GITLAB_USER_NAME**                      | 10.0   | all    | The real name of the user who started the job |
| **RESTORE_CACHE_ATTEMPTS**                | 8.15   | 1.9    | Number of attempts to restore the cache running a job |
Douwe Maan's avatar
Douwe Maan включено в состав коммита
143

Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
144
## GitLab 9.0 renaming
Z.J. van de Weg's avatar
Z.J. van de Weg включено в состав коммита
145

Ville Skyttä's avatar
Ville Skyttä включено в состав коммита
146
To follow conventions of naming across GitLab, and to further move away from the
Z.J. van de Weg's avatar
Z.J. van de Weg включено в состав коммита
147
148
149
`build` term and toward `job` CI variables have been renamed for the 9.0
release.

Evan Read's avatar
Evan Read включено в состав коммита
150
NOTE: **Note:**
Fabio Busatto's avatar
Fabio Busatto включено в состав коммита
151
152
153
154
Starting with GitLab 9.0, we have deprecated the `$CI_BUILD_*` variables. **You are
strongly advised to use the new variables as we will remove the old ones in
future GitLab releases.**

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
155
156
157
158
159
| 8.x name              | 9.0+ name               |
| --------------------- |------------------------ |
| `CI_BUILD_ID`         | `CI_JOB_ID`             |
| `CI_BUILD_REF`        | `CI_COMMIT_SHA`         |
| `CI_BUILD_TAG`        | `CI_COMMIT_TAG`         |
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
160
| `CI_BUILD_BEFORE_SHA` | `CI_COMMIT_BEFORE_SHA`  |
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
161
162
163
164
| `CI_BUILD_REF_NAME`   | `CI_COMMIT_REF_NAME`    |
| `CI_BUILD_REF_SLUG`   | `CI_COMMIT_REF_SLUG`    |
| `CI_BUILD_NAME`       | `CI_JOB_NAME`           |
| `CI_BUILD_STAGE`      | `CI_JOB_STAGE`          |
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
165
| `CI_BUILD_REPO`       | `CI_REPOSITORY_URL`     |
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
166
167
168
| `CI_BUILD_TRIGGERED`  | `CI_PIPELINE_TRIGGERED` |
| `CI_BUILD_MANUAL`     | `CI_JOB_MANUAL`         |
| `CI_BUILD_TOKEN`      | `CI_JOB_TOKEN`          |
Z.J. van de Weg's avatar
Z.J. van de Weg включено в состав коммита
169

Mathijs de Kruyf's avatar
Mathijs de Kruyf включено в состав коммита
170
## `.gitlab-ci.yml` defined variables
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
171

Evan Read's avatar
Evan Read включено в состав коммита
172
NOTE **Note:**
Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
173
This feature requires GitLab Runner 0.5.0 or higher and GitLab 7.14 or higher.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
174

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
175
176
GitLab CI allows you to add to `.gitlab-ci.yml` variables that are set in the
build environment. The variables are hence saved in the repository, and they
Evan Read's avatar
Evan Read включено в состав коммита
177
are meant to store non-sensitive project configuration. For example, `RAILS_ENV` or
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
178
179
180
181
`DATABASE_URL`.

For example, if you set the variable below globally (not inside a job), it will
be used in all executed commands and scripts:
Douwe Maan's avatar
Douwe Maan включено в состав коммита
182
183
184
185
186
187

```yaml
variables:
  DATABASE_URL: "postgres://postgres@postgres/my_database"
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
188
189
190
191
192
The YAML-defined variables are also set to all created
[service containers](../docker/using_docker_images.md), thus allowing to fine
tune them.

Variables can be defined at a global level, but also at a job level. To turn off
Tor Bechmann Yamamoto-Sørensen's avatar
Tor Bechmann Yamamoto-Sørensen включено в состав коммита
193
global defined variables in your job, define an empty hash:
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
194
195
196

```yaml
job_name:
Sébastien's avatar
Sébastien включено в состав коммита
197
  variables: {}
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
198
199
```

TeNNoX's avatar
TeNNoX включено в состав коммита
200
201
202
203
204
205
206
207
208
209
You are able to use other variables inside your variable definition (or escape them with `$$`):

```yaml
variables:
  LS_CMD: 'ls $FLAGS $$TMP_DIR'
  FLAGS: '-al'
script:
  - 'eval $LS_CMD'  # will execute 'ls -al $TMP_DIR'
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
210
## Variables
Douwe Maan's avatar
Douwe Maan включено в состав коммита
211

Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
212
> Group-level variables were introduced in GitLab 9.4.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
213
214

CAUTION: **Important:**
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
215
Be aware that variables are not masked, and their values can be shown
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
216
217
218
in the job logs if explicitly asked to do so. If your project is public or
internal, you can set the pipelines private from your [project's Pipelines
settings](../../user/project/pipelines/settings.md#visibility-of-pipelines).
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
219
Follow the discussion in issue [#13784][ce-13784] for masking the variables.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
220

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
221
222
GitLab CI allows you to define per-project or per-group variables
that are set in the pipeline environment. The variables are stored out of
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
223
224
the repository (not in `.gitlab-ci.yml`) and are securely passed to GitLab Runner
making them available during a pipeline run. It's the recommended method to
Evan Read's avatar
Evan Read включено в состав коммита
225
226
227
use for storing things like passwords, SSH keys, and credentials.

Project-level variables can be added by:
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
228

Evan Read's avatar
Evan Read включено в состав коммита
229
230
1. Navigating to your project's **Settings > CI/CD** page.
1. Inputing variable keys and values in the **Environment variables** section.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
231

Evan Read's avatar
Evan Read включено в состав коммита
232
Group-level variables can be added by:
Douwe Maan's avatar
Douwe Maan включено в состав коммита
233

Evan Read's avatar
Evan Read включено в состав коммита
234
235
236
1. Navigating to your group's **Settings > CI/CD** page.
1. Inputing variable keys and values in the **Environment variables** section. Any variables of
   [subgroups](../../user/group/subgroups/index.md) will be inherited recursively.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
237

Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
238
Once you set them, they will be available for all subsequent pipelines. You can also
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
239
[protect your variables](#protected-variables).
Lin Jen-Shin's avatar
Lin Jen-Shin включено в состав коммита
240

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
241
### Protected variables
Lin Jen-Shin's avatar
Lin Jen-Shin включено в состав коммита
242

Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
243
> Introduced in GitLab 9.3.
Lin Jen-Shin's avatar
Lin Jen-Shin включено в состав коммита
244

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
245
Variables could be protected. Whenever a variable is
Lin Jen-Shin's avatar
Lin Jen-Shin включено в состав коммита
246
protected, it would only be securely passed to pipelines running on the
Lin Jen-Shin's avatar
Lin Jen-Shin включено в состав коммита
247
[protected branches] or [protected tags]. The other pipelines would not get any
Lin Jen-Shin's avatar
Lin Jen-Shin включено в состав коммита
248
249
250
protected variables.

Protected variables can be added by going to your project's
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
251
**Settings > CI/CD**, then finding the section called
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
252
**Variables**, and check "Protected".
Lin Jen-Shin's avatar
Lin Jen-Shin включено в состав коммита
253
254

Once you set them, they will be available for all subsequent pipelines.
Nick Thomas's avatar
Nick Thomas включено в состав коммита
255

Evan Read's avatar
Evan Read включено в состав коммита
256
257
258
259
260
261
### Manually-specified variables

> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/issues/44059) in GitLab 10.8.

Variables can be specified for a single pipeline run when a [manual pipeline](../pipelines.md#manually-executing-pipelines) is created.

Adam Niedzielski's avatar
Adam Niedzielski включено в состав коммита
262
263
## Deployment variables

Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
264
> Introduced in GitLab 8.15.
Adam Niedzielski's avatar
Adam Niedzielski включено в состав коммита
265

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
266
[Project services](../../user/project/integrations/project_services.md) that are
Adam Niedzielski's avatar
Adam Niedzielski включено в состав коммита
267
268
responsible for deployment configuration may define their own variables that
are set in the build environment. These variables are only defined for
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
269
[deployment jobs](../environments.md). Please consult the documentation of
Adam Niedzielski's avatar
Adam Niedzielski включено в состав коммита
270
271
the project services that you are using to learn which variables they define.

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
272
273
An example project service that defines deployment variables is the
[Kubernetes integration](../../user/project/clusters/index.md#deployment-variables).
Adam Niedzielski's avatar
Adam Niedzielski включено в состав коммита
274

Thong Kuah's avatar
Thong Kuah включено в состав коммита
275
276
277
278
279
280
281
282
283
284
285
286
287
## Auto DevOps application variables

> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/issues/49056) in GitLab 11.7.

You can configure [Auto DevOps](../../topics/autodevops/index.md) to
pass CI variables to the running application by prefixing the key of the
variable with `K8S_SECRET_`.

These [prefixed
variables](../../topics/autodevops/index.md#application-secret-variables) will
then be available as environment variables on the running application
container.

Thong Kuah's avatar
Thong Kuah включено в состав коммита
288
CAUTION: **Caution:**
Thong Kuah's avatar
Thong Kuah включено в состав коммита
289
Variables with multiline values are not currently supported due to
Thong Kuah's avatar
Thong Kuah включено в состав коммита
290
291
limitations with the current Auto DevOps scripting environment.

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
292
293
294
## Debug tracing

> Introduced in GitLab Runner 1.7.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
295
296
297

CAUTION: **Warning:**
Enabling debug tracing can have severe security implications. The
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
298
output **will** contain the content of all your variables and any other
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
299
300
secrets! The output **will** be uploaded to the GitLab server and made visible
in job traces!
Nick Thomas's avatar
Nick Thomas включено в состав коммита
301
302

By default, GitLab Runner hides most of the details of what it is doing when
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
303
processing a job. This behavior keeps job traces short, and prevents secrets
Nick Thomas's avatar
Nick Thomas включено в состав коммита
304
305
306
307
308
from being leaked into the trace unless your script writes them to the screen.

If a job isn't working as expected, this can make the problem difficult to
investigate; in these cases, you can enable debug tracing in `.gitlab-ci.yml`.
Available on GitLab Runner v1.7+, this feature enables the shell's execution
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
309
trace, resulting in a verbose job trace listing all commands that were run,
Nick Thomas's avatar
Nick Thomas включено в состав коммита
310
311
variables that were set, etc.

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
312
Before enabling this, you should ensure jobs are visible to
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
313
[team members only](../../user/permissions.md#project-features). You should
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
314
also [erase](../pipelines.md#seeing-build-status) all generated job traces
Nick Thomas's avatar
Nick Thomas включено в состав коммита
315
316
317
318
319
before making them visible again.

To enable debug traces, set the `CI_DEBUG_TRACE` variable to `true`:

```yaml
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
320
job_name:
Nick Thomas's avatar
Nick Thomas включено в состав коммита
321
322
323
324
  variables:
    CI_DEBUG_TRACE: "true"
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
Example truncated output with debug trace set to true:

```bash
...

export CI_SERVER_TLS_CA_FILE="/builds/gitlab-examples/ci-debug-trace.tmp/CI_SERVER_TLS_CA_FILE"
if [[ -d "/builds/gitlab-examples/ci-debug-trace/.git" ]]; then
  echo $'\''\x1b[32;1mFetching changes...\x1b[0;m'\''
  $'\''cd'\'' "/builds/gitlab-examples/ci-debug-trace"
  $'\''git'\'' "config" "fetch.recurseSubmodules" "false"
  $'\''rm'\'' "-f" ".git/index.lock"
  $'\''git'\'' "clean" "-ffdx"
  $'\''git'\'' "reset" "--hard"
  $'\''git'\'' "remote" "set-url" "origin" "https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@example.com/gitlab-examples/ci-debug-trace.git"
  $'\''git'\'' "fetch" "origin" "--prune" "+refs/heads/*:refs/remotes/origin/*" "+refs/tags/*:refs/tags/*"
else
  $'\''mkdir'\'' "-p" "/builds/gitlab-examples/ci-debug-trace.tmp/git-template"
  $'\''rm'\'' "-r" "-f" "/builds/gitlab-examples/ci-debug-trace"
  $'\''git'\'' "config" "-f" "/builds/gitlab-examples/ci-debug-trace.tmp/git-template/config" "fetch.recurseSubmodules" "false"
  echo $'\''\x1b[32;1mCloning repository...\x1b[0;m'\''
  $'\''git'\'' "clone" "--no-checkout" "https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@example.com/gitlab-examples/ci-debug-trace.git" "/builds/gitlab-examples/ci-debug-trace" "--template" "/builds/gitlab-examples/ci-debug-trace.tmp/git-template"
  $'\''cd'\'' "/builds/gitlab-examples/ci-debug-trace"
fi
echo $'\''\x1b[32;1mChecking out dd648b2e as master...\x1b[0;m'\''
$'\''git'\'' "checkout" "-f" "-q" "dd648b2e48ce6518303b0bb580b2ee32fadaf045"
'
+++ hostname
++ echo 'Running on runner-8a2f473d-project-1796893-concurrent-0 via runner-8a2f473d-machine-1480971377-317a7d0f-digital-ocean-4gb...'
Running on runner-8a2f473d-project-1796893-concurrent-0 via runner-8a2f473d-machine-1480971377-317a7d0f-digital-ocean-4gb...
++ export CI=true
++ CI=true
++ export CI_DEBUG_TRACE=false
++ CI_DEBUG_TRACE=false
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg включено в состав коммита
358
359
++ export CI_COMMIT_SHA=dd648b2e48ce6518303b0bb580b2ee32fadaf045
++ CI_COMMIT_SHA=dd648b2e48ce6518303b0bb580b2ee32fadaf045
Jason Lenny's avatar
Jason Lenny включено в состав коммита
360
361
++ export CI_COMMIT_SHORT_SHA=dd648b2e
++ CI_COMMIT_SHORT_SHA=dd648b2e
Z.J. van de Weg's avatar
Z.J. van de Weg включено в состав коммита
362
363
364
365
366
367
368
369
370
371
++ export CI_COMMIT_BEFORE_SHA=dd648b2e48ce6518303b0bb580b2ee32fadaf045
++ CI_COMMIT_BEFORE_SHA=dd648b2e48ce6518303b0bb580b2ee32fadaf045
++ export CI_COMMIT_REF_NAME=master
++ CI_COMMIT_REF_NAME=master
++ export CI_JOB_ID=7046507
++ CI_JOB_ID=7046507
++ export CI_REPOSITORY_URL=https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@example.com/gitlab-examples/ci-debug-trace.git
++ CI_REPOSITORY_URL=https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@example.com/gitlab-examples/ci-debug-trace.git
++ export CI_JOB_TOKEN=xxxxxxxxxxxxxxxxxxxx
++ CI_JOB_TOKEN=xxxxxxxxxxxxxxxxxxxx
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
372
373
374
375
376
377
378
379
380
381
++ export CI_PROJECT_ID=1796893
++ CI_PROJECT_ID=1796893
++ export CI_PROJECT_DIR=/builds/gitlab-examples/ci-debug-trace
++ CI_PROJECT_DIR=/builds/gitlab-examples/ci-debug-trace
++ export CI_SERVER=yes
++ CI_SERVER=yes
++ export 'CI_SERVER_NAME=GitLab CI'
++ CI_SERVER_NAME='GitLab CI'
++ export CI_SERVER_VERSION=
++ CI_SERVER_VERSION=
Gilbert Roulot's avatar
Gilbert Roulot включено в состав коммита
382
383
384
385
386
387
++ export CI_SERVER_VERSION_MAJOR=
++ CI_SERVER_VERSION_MAJOR=
++ export CI_SERVER_VERSION_MINOR=
++ CI_SERVER_VERSION_MINOR=
++ export CI_SERVER_VERSION_PATCH=
++ CI_SERVER_VERSION_PATCH=
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
388
389
390
391
392
393
394
395
++ export CI_SERVER_REVISION=
++ CI_SERVER_REVISION=
++ export GITLAB_CI=true
++ GITLAB_CI=true
++ export CI=true
++ CI=true
++ export GITLAB_CI=true
++ GITLAB_CI=true
Z.J. van de Weg's avatar
Z.J. van de Weg включено в состав коммита
396
397
398
399
400
401
402
403
404
405
406
407
408
409
++ export CI_JOB_ID=7046507
++ CI_JOB_ID=7046507
++ export CI_JOB_TOKEN=xxxxxxxxxxxxxxxxxxxx
++ CI_JOB_TOKEN=xxxxxxxxxxxxxxxxxxxx
++ export CI_COMMIT_REF=dd648b2e48ce6518303b0bb580b2ee32fadaf045
++ CI_COMMIT_REF=dd648b2e48ce6518303b0bb580b2ee32fadaf045
++ export CI_COMMIT_BEFORE_SHA=dd648b2e48ce6518303b0bb580b2ee32fadaf045
++ CI_COMMIT_BEFORE_SHA=dd648b2e48ce6518303b0bb580b2ee32fadaf045
++ export CI_COMMIT_REF_NAME=master
++ CI_COMMIT_REF_NAME=master
++ export CI_COMMIT_NAME=debug_trace
++ CI_JOB_NAME=debug_trace
++ export CI_JOB_STAGE=test
++ CI_JOB_STAGE=test
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
410
411
412
413
414
415
++ export CI_SERVER_NAME=GitLab
++ CI_SERVER_NAME=GitLab
++ export CI_SERVER_VERSION=8.14.3-ee
++ CI_SERVER_VERSION=8.14.3-ee
++ export CI_SERVER_REVISION=82823
++ CI_SERVER_REVISION=82823
Adrian Moisey's avatar
Adrian Moisey включено в состав коммита
416
417
418
419
++ export CI_PAGES_DOMAIN=gitlab.io
++ CI_PAGES_DOMAIN=gitlab.io
++ export CI_PAGES_URL=https://gitlab-examples.gitlab.io/ci-debug-trace
++ CI_PAGES_URL=https://gitlab-examples.gitlab.io/ci-debug-trace
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
420
421
422
423
424
425
426
427
428
429
430
431
++ export CI_PROJECT_ID=17893
++ CI_PROJECT_ID=17893
++ export CI_PROJECT_NAME=ci-debug-trace
++ CI_PROJECT_NAME=ci-debug-trace
++ export CI_PROJECT_PATH=gitlab-examples/ci-debug-trace
++ CI_PROJECT_PATH=gitlab-examples/ci-debug-trace
++ export CI_PROJECT_NAMESPACE=gitlab-examples
++ CI_PROJECT_NAMESPACE=gitlab-examples
++ export CI_PROJECT_URL=https://example.com/gitlab-examples/ci-debug-trace
++ CI_PROJECT_URL=https://example.com/gitlab-examples/ci-debug-trace
++ export CI_PIPELINE_ID=52666
++ CI_PIPELINE_ID=52666
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
432
433
++ export CI_PIPELINE_IID=123
++ CI_PIPELINE_IID=123
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
434
435
436
437
++ export CI_RUNNER_ID=1337
++ CI_RUNNER_ID=1337
++ export CI_RUNNER_DESCRIPTION=shared-runners-manager-1.example.com
++ CI_RUNNER_DESCRIPTION=shared-runners-manager-1.example.com
Pawel Chojnacki's avatar
Pawel Chojnacki включено в состав коммита
438
439
++ export 'CI_RUNNER_TAGS=shared, docker, linux, ruby, mysql, postgres, mongo'
++ CI_RUNNER_TAGS='shared, docker, linux, ruby, mysql, postgres, mongo'
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
440
441
442
443
444
445
446
++ export CI_REGISTRY=registry.example.com
++ CI_REGISTRY=registry.example.com
++ export CI_DEBUG_TRACE=true
++ CI_DEBUG_TRACE=true
++ export GITLAB_USER_ID=42
++ GITLAB_USER_ID=42
++ export GITLAB_USER_EMAIL=user@example.com
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
447
++ GITLAB_USER_EMAIL=user@example.com
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
448
449
450
451
452
453
454
455
++ export VERY_SECURE_VARIABLE=imaverysecurevariable
++ VERY_SECURE_VARIABLE=imaverysecurevariable
++ mkdir -p /builds/gitlab-examples/ci-debug-trace.tmp
++ echo -n '-----BEGIN CERTIFICATE-----
MIIFQzCCBCugAwIBAgIRAL/ElDjuf15xwja1ZnCocWAwDQYJKoZIhvcNAQELBQAw'

...
```
Nick Thomas's avatar
Nick Thomas включено в состав коммита
456

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
457
## Using the CI variables in your job scripts
Douwe Maan's avatar
Douwe Maan включено в состав коммита
458

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
459
460
All variables are set as environment variables in the build environment, and
they are accessible with normal methods that are used to access such variables.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
461
In most cases `bash` or `sh` is used to execute the job script.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
462

John Spaetzel's avatar
John Spaetzel включено в состав коммита
463
To access environment variables, use the syntax for your Runner's [shell][shellexecutors].
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
464

John Spaetzel's avatar
John Spaetzel включено в состав коммита
465
466
467
468
469
470
471
472
473
| Shell                | Usage           |
|----------------------|-----------------|
| bash/sh              | `$variable`     |
| windows batch        | `%variable%`    |
| PowerShell           | `$env:variable` |

To access environment variables in bash, prefix the variable name with (`$`):

```yaml
Douwe Maan's avatar
Douwe Maan включено в состав коммита
474
475
job_name:
  script:
Elan Ruusamäe's avatar
Elan Ruusamäe включено в состав коммита
476
    - echo $CI_JOB_ID
Douwe Maan's avatar
Douwe Maan включено в состав коммита
477
478
```

John Spaetzel's avatar
John Spaetzel включено в состав коммита
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
To access environment variables in **Windows Batch**, surround the variable
with (`%`):

```yaml
job_name:
  script:
    - echo %CI_JOB_ID%
```

To access environment variables in a **Windows PowerShell** environment, prefix
the variable name with (`$env:`):

```yaml
job_name:
  script:
    - echo $env:CI_JOB_ID
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
497
You can also list all environment variables with the `export` command,
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
498
but be aware that this will also expose the values of all the variables
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
499
you set, in the job log:
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
500

John Spaetzel's avatar
John Spaetzel включено в состав коммита
501
```yaml
Douwe Maan's avatar
Douwe Maan включено в состав коммита
502
503
504
505
job_name:
  script:
    - export
```
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
506

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
507
508
509
510
511
Example values:

```bash
export CI_JOB_ID="50"
export CI_COMMIT_SHA="1ecfd275763eff1d6b4844ea3168962458c9f27a"
Jason Lenny's avatar
Jason Lenny включено в состав коммита
512
export CI_COMMIT_SHORT_SHA="1ecfd275"
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
513
export CI_COMMIT_REF_NAME="master"
Mustafa YILDIRIM's avatar
Mustafa YILDIRIM включено в состав коммита
514
export CI_REPOSITORY_URL="https://gitlab-ci-token:abcde-1234ABCD5678ef@example.com/gitlab-org/gitlab-ce.git"
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
515
516
517
518
519
520
521
export CI_COMMIT_TAG="1.0.0"
export CI_JOB_NAME="spec:other"
export CI_JOB_STAGE="test"
export CI_JOB_MANUAL="true"
export CI_JOB_TRIGGERED="true"
export CI_JOB_TOKEN="abcde-1234ABCD5678ef"
export CI_PIPELINE_ID="1000"
Shinya Maeda's avatar
Shinya Maeda включено в состав коммита
522
export CI_PIPELINE_IID="10"
Adrian Moisey's avatar
Adrian Moisey включено в состав коммита
523
524
export CI_PAGES_DOMAIN="gitlab.io"
export CI_PAGES_URL="https://gitlab-org.gitlab.io/gitlab-ce"
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
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://example.com/gitlab-org/gitlab-ce"
export CI_REGISTRY="registry.example.com"
export CI_REGISTRY_IMAGE="registry.example.com/gitlab-org/gitlab-ce"
export CI_RUNNER_ID="10"
export CI_RUNNER_DESCRIPTION="my runner"
export CI_RUNNER_TAGS="docker, linux"
export CI_SERVER="yes"
export CI_SERVER_NAME="GitLab"
export CI_SERVER_REVISION="70606bf"
export CI_SERVER_VERSION="8.9.0"
Gilbert Roulot's avatar
Gilbert Roulot включено в состав коммита
540
541
542
export CI_SERVER_VERSION_MAJOR="8"
export CI_SERVER_VERSION_MINOR="9"
export CI_SERVER_VERSION_PATCH="0"
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
543
544
545
546
547
548
export GITLAB_USER_ID="42"
export GITLAB_USER_EMAIL="user@example.com"
export CI_REGISTRY_USER="gitlab-ci-token"
export CI_REGISTRY_PASSWORD="longalfanumstring"
```

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
549
550
## Variables expressions

Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
551
> Introduced in GitLab 10.7.
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
552
553

It is possible to use variables expressions with only / except policies in
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
554
555
`.gitlab-ci.yml`. By using this approach you can limit what jobs are going to
be created within a pipeline after pushing a code to GitLab.
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
556

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
557
This is particularly useful in combination with variables and triggered
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
558
559
560
561
562
563
564
565
566
567
568
569
pipeline variables.

```yaml
deploy:
  script: cap staging deploy
  environment: staging
  only:
    variables:
      - $RELEASE == "staging"
      - $STAGING
```

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
570
Each expression provided is going to be evaluated before creating a pipeline.
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
571
572

If any of the conditions in `variables` evaluates to truth when using `only`,
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
573
574
a new job is going to be created. If any of the expressions evaluates to truth
when `except` is being used, a job is not going to be created.
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
575

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
576
This follows usual rules for [`only` / `except` policies][builds-policies].
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
577
578
579

### Supported syntax

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
580
Below you can find supported syntax reference:
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
581

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
582
1. Equality matching using a string
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
583

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
584
    > Example: `$VARIABLE == "some value"`
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
585
586
587
588
589
590

    You can use equality operator `==` to compare a variable content to a
    string. We support both, double quotes and single quotes to define a string
    value, so both `$VARIABLE == "some value"` and `$VARIABLE == 'some value'`
    are supported. `"some value" == $VARIABLE` is correct too.

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
591
1. Checking for an undefined value
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
592

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
593
594
595
596
    > Example: `$VARIABLE == null`

    It sometimes happens that you want to check whether a variable is defined
    or not. To do that, you can compare a variable to `null` keyword, like
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
597
    `$VARIABLE == null`. This expression is going to evaluate to truth if
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
598
    variable is not defined.
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
599

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
600
601
1. Checking for an empty variable

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
602
603
    > Example: `$VARIABLE == ""`

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
604
605
606
607
    If you want to check whether a variable is defined, but is empty, you can
    simply compare it against an empty string, like `$VAR == ''`.

1. Comparing two variables
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
608

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
609
610
611
612
    > Example: `$VARIABLE_1 == $VARIABLE_2`

    It is possible to compare two variables. This is going to compare values
    of these variables.
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
613

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
614
1. Variable presence check
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
615

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
616
617
    > Example: `$STAGING`

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
618
619
620
621
    If you only want to create a job when there is some variable present,
    which means that it is defined and non-empty, you can simply use
    variable name as an expression, like `$STAGING`. If `$STAGING` variable
    is defined, and is non empty, expression will evaluate to truth.
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
622
623
624
    `$STAGING` value needs to a string, with length higher than zero.
    Variable that contains only whitespace characters is not an empty variable.

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
625
626
627
628
629
630
631
1. Pattern matching  _(added in 11.0)_

    > Example: `$VARIABLE =~ /^content.*/`

    It is possible perform pattern matching against a variable and regular
    expression. Expression like this evaluates to truth if matches are found.

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
632
633
    Pattern matching is case-sensitive by default. Use `i` flag modifier, like
    `/pattern/i` to make a pattern case-insensitive.
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
634

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
635
[ce-13784]: https://gitlab.com/gitlab-org/gitlab-ce/issues/13784 "Simple protection of CI variables"
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
636
[eep]: https://about.gitlab.com/pricing/ "Available only in GitLab Premium"
Lin Jen-Shin's avatar
Lin Jen-Shin включено в состав коммита
637
[envs]: ../environments.md
Lin Jen-Shin's avatar
Lin Jen-Shin включено в состав коммита
638
639
[protected branches]: ../../user/project/protected_branches.md
[protected tags]: ../../user/project/protected_tags.md
John Spaetzel's avatar
John Spaetzel включено в состав коммита
640
[shellexecutors]: https://docs.gitlab.com/runner/executors/
Lin Jen-Shin's avatar
Lin Jen-Shin включено в состав коммита
641
[triggered]: ../triggers/README.md
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
642
[builds-policies]: ../yaml/README.md#only-and-except-complex
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
643
[gitlab-deploy-token]: ../../user/project/deploy_tokens/index.md#gitlab-deploy-token
Steve Azzopardi's avatar
Steve Azzopardi включено в состав коммита
644
[registry]: ../../user/project/container_registry.md
Evan Read's avatar
Evan Read включено в состав коммита
645
[dependent-repositories]: ../../user/project/new_ci_build_permissions_model.md#dependent-repositories