Environment variables are extremely useful as they bring a lot of flexibility to CI/CD jobs and pipelines in GitLab.
There are some predefined variables that are available in every GitLab CI/CD pipeline and custom variables that can be defined in different ways.
In this short note i will show how to list all the environment variables in GitLab CI/CD and print their values.
Cool Tip: Ansible Playbook – Print Variable & List All Variables! Read more →
Print All Environment Variables in GitLab CI/CD
To print all the environment variables set inside a GitLab CI/CD runner, create a .gitlab-ci.yml
file with the contents as follows, or add this snipped to the already existent pipeline:
# .gitlab-ci.yml
stages:
- debug
print-all-env-vars-job:
stage: debug
script:
- echo "GitLab CI/CD | Print all environment variables"
- env
Commit and push to remote to trigger the pipeline:
$ git add .gitlab-ci.yml $ git commit -m "Print all environment variables" $ git push
On a GitLab’s UI, the above job should produce the output as follows:
... $ echo "GitLab CI/CD | Print all environment variables" GitLab CI/CD | Print all environment variables $ env CI_PROJECT_NAMESPACE=<userName> GITLAB_USER_ID=<userId> CI_RUNNER_VERSION=14.4.0-rc1 FF_SKIP_NOOP_BUILD_STAGES=true CI_SERVER_NAME=GitLab CI_RUNNER_DESCRIPTION=2-blue.shared.runners-manager.gitlab.com/default GITLAB_USER_EMAIL=<userEmail> CI_SERVER_REVISION=a01125bc237 FF_USE_WINDOWS_LEGACY_PROCESS_STRATEGY=true CI_RUNNER_EXECUTABLE_ARCH=linux/amd64 ...
very good & instructive
Oh that’s what that password was! I’ve been trying to figure that out. = )
Thank you! My only issue was not knowing where to look for the output, but eventually I located the new debug step in the pipeline list and got the output I needed.
The “debug” stage does not exist and I got a yaml invalid error. Using the “.pre” stage worked though.
Thanks, Thomas