# Environment variables
# Overview
An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs. Programs use environment variables to determine how to act according to the environment they run on.
You may use environment varialbes to define configuration values for your build script.
# Using environment variables
Environment variables can be used in your job script. Predefined variables can also be used in some other config values.
You can use any syntax available to the shell running in the container.
jobs:
build:
stage: build
image: alpine
script:
- echo $CI_BRANCH # e.g: master
- echo $YOUR_SECRET # your secret value
- echo ${CI_COMMIT_HASH:0:7} # the commit sha truncated to 7 characters
- echo ${NAME:-default-name} # default value
Any environment variable predefined by the shell or the docker image can also be used.
jobs:
build:
stage: build
image: node
script:
- echo $PWD # print current working directory
- echo $NODE_VERSION # NodeJS version
You can also define environment variables in runtime using the export
command available in UNIX shells.
jobs:
build:
stage: build
image: node
script:
- export APP_NAME="my app"
- echo $APP_NAME # my app
It's particularly helpful when you want to define a variable based on some condition.
Note that although you can use number or boolean in the config file, environment variables are always string in your application.
# Types of environment variables
There are three types of variables available as environment variables for every job: