Public
Authored by Dan Thomson

Print Gitlab CI/CD Variables as Environment Variables

Downloading and running this script locally can be done with either of the following commands:

$ curl -o gitlab-ci-env.sh https://gitlab.triumf.ca/snippets/58/raw
$ chmod 755 ./gitlab-ci-env.sh
$ ./gitlab-ci-env.sh

or by piping the script directly into bash:

$ curl https://gitlab.triumf.ca/snippets/58/raw | bash -

or by piping into bash and providing an argument (our private token file at /tmp/private-token):

$ curl https://gitlab.triumf.ca/snippets/58/raw | bash -s -- -p /tmp/private-token

You can use this script to pull your CI/CD variables out of a Gitlab project's CI/CD script (eg. your .gitlab-ci.yml) and print them as they would be printed to set the value in your bash shell (this probably only works with bash and zsh). If you eval the output from this script, you can automatically have those values exported into your environment. Eg:

$~ cd myproject
$~/myproject eval $(gitlab-ci-env.sh)

This script is very simple but when coupled with the project variable script, you can export all relevant values from a project into your environment in order to easily debug your deployment without having to run the pipeline for every minor change.

Edited
gitlab-ci-env.sh 9.58 KB
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