Commit d69cb658 authored by Krasimir Angelov's avatar Krasimir Angelov Committed by Achilleas Pipinellis

Add CI variable types usage example

Update documentation with example how to use CI variable types.

Related to https://gitlab.com/gitlab-org/gitlab-ce/issues/46806.
parent b3a2d8d6
......@@ -58,8 +58,29 @@ the need to specify the value itself.
There are two types of variables supported by GitLab:
- `env_var`: the runner will create environment variable named same as the variable key and set its value to the variable value.
- `file`: the runner will write the variable value to a temporary file and set the path to this file as the value of an environment variable named same as the variable key.
- "Variable": the Runner will create an environment variable named same as the variable key and set its value to the variable value.
- "File": the Runner will write the variable value to a temporary file and set the path to this file as the value of an environment variable named same as the variable key.
Many tools (like [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html) and [kubectl](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#the-kubeconfig-environment-variable)) provide the ability to customise configuration using files by either providing the file path as a command line argument or an environment variable. Prior to the introduction of variable types, the common pattern was to use the value of a CI variable, save it in a file, and then use the newly created file in your script:
```bash
# Save the content of variable in a file
echo "$KUBE_CA_PEM" > "$(pwd)/kube.ca.pem"
# Use the newly created file
kubectl config set-cluster e2e --server="$KUBE_URL" --certificate-authority="$(pwd)/kube.ca.pem"
```
This can be simplified by creating a variable of type "File" and using it directly. For example, let's say we have the following variables.
![CI/CD settings - variable types usage example](img/variable_types_usage_example.png)
We can then call them from `.gitlab-ci.yml` like this:
```bash
kubectl config set-cluster e2e --server="$KUBE_URL" --certificate-authority="$KUBE_CA_PEM"
```
Variable types can be set via the [UI](#via-the-ui) or the [API](../../api/project_level_variables.md#create-variable), but not in `.gitlab-ci.yml`.
#### Masked variables
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment