An environment variable is a dynamic-named value that can affect how running processes behave on a host.
They are part of the environment in which a process runs. For example, a running process can query the value of the TEMP environment variable to discover a suitable location to store temporary files, or the HOME or USERPROFILE variable to find the directory structure owned by the user running the process.
The built-in and user-defined variables are passed to the build containers as
environment variables. They invoked in your pipelines by adding
front of the variable name like as following:
where DOCKER_REGISTRY is the name of the variable to print.
Built-in environment variables
||The unique pipeline ID, can be used as an identifier of the build.|
||The unique job ID.|
||The stage of the job as defined in the pipeline config.|
||The name of the job as defined in the pipeline config.|
||The branch of a commit that triggered the pipeline.|
||The tag of a commit that triggered the pipeline. Available only on tags.|
||The unique commit has of a commit that triggered the pipeline.|
||The short representation of
||The absolute path of the directory that contains the repository. It is also set to current working directory.|
||The ID of the Pull Request triggered the pipeline.|
||The key of the project which repository belongs to.|
||The name of the project which repository belongs to.|
||The unique ID of the project which repository belongs to.|
||The repository slug (can be useful for URLs)|
||The repository name.|
||The unique ID of the repository.|
||The URL used to clone the repository.|
||The unique ID of the runner where the pipeline is running.|
||The name of the runner where the pipeline is running|
||The version of the runner where the pipeline is runner|
Repository environment variables
Environment Variables settings can be accessed by the following path: Repository → Repository Settings → CI/CD → Variables
You can add, delete or modify environment variables on a repository level, it can
is useful for teams because only a user with
admin privileges can access
the Repository Settings page.
Variables can contain multi-line breaks, you don’t need to encode it into Base64 and decode it in the container. Just put it as is, just like that.
Pipeline environment variables (YAML)
You can also specify variables using the
variables section in the pipeline.
There are two levels:
- pipeline variables — available for all jobs
- job variables — available only for the specified job
image: alpine variables: PIPELINE_WIDE: "available for all jobs" stages: - test - build run tests: stage: test variables: TEST: "available only for run tests" commands: - "echo PIPELINE_WIDE: $PIPELINE_WIDE" - "echo TEST: $TEST" compile code: stage: build variables: BUILD_FOO: "foo; only for build" commands: - "echo PIPELINE_WIDE: $PIPELINE_WIDE" - "echo TEST: $TEST" # will be empty - "echo BUILD_FOO: $BUILD_FOO"