GitLab CI/CD: Print All Environment Variables

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

  - debug

  stage: debug
    - 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
Was it useful? Share this post with the world!

4 Replies to “GitLab CI/CD: Print All Environment Variables”

  1. very good & instructive

  2. Oh that’s what that password was! I’ve been trying to figure that out. = )

  3. 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.

  4. The “debug” stage does not exist and I got a yaml invalid error. Using the “.pre” stage worked though.
    Thanks, Thomas

Leave a Reply