Tool to get the environment variables of a gitlab project or gitlab group.
- This tool does not initiliaze the predefinid variables.
- It does not care of variables declared in .gitlab-ci.yml file
- But you can simulate some vars by creating a .gitlab-vars.json file (see below)
Usage: gitlab-vars [options]
Options:
-g <group_id> Group id
-p <project_id> Project id
-e <environment> Environment
-h Help
-d <debuglevel> Debug level (info, error, debug)
-v Version
gitlab-vars is a tool to print the variables of a gitlab project. You can use it to check how variables will be overrided.
But don't expect from this tool to give you the value of the variables after a workflow for example.
It won't read .gitlab-ci.yml file.
Every parameters are optionals.
By default, gitlab-vars try to find the project id from the current git repository.
How it works ?
1. Find the .git directory
2. Read the git config file
3. Get the remote origin url
4. Find the project id from the remote origin url
If the project id is not found, you can specify the group id or the project id.
Copy the binary to /usr/local/bin for example. (or another directory which is in your PATH).
2 environment variables can be set :
- GITLAB_TOKEN: used to access to the gitlab API
- GITLAB_URI: to specify another instance of Gitlab (if not set, GITLAB_URI is set to https://gitlab.com)
$ git clone git@gitlab.com:group/awesome-project.git
$ cd awesome-project
$ gitlab-vars
gitlab-vars -g XXXXXX
gitlab-vars -p XXXXXX
cd .../gitlab-cloned-project
gitlab-vars
cd .../gitlab-cloned-project
gitlab-vars -e production
cat > .gitlab-vars.json <<EOF
{
"variables": [
{
"variable_type": "string",
"key": "variable_key",
"value": "value",
"protected": false,
"masked": false,
"raw": false,
"environment_scope": ""
},
{
"variable_type": "string",
"key": "variable_key2",
"value": "value2",
"protected": false,
"masked": false,
"raw": false,
"environment_scope": "prod"
}
]
}
EOF
$ gitlab-vars
...
envtemplate is a project to generate files from templates according to environment variables.
Example:
$ cat tmpl
{{ .REGISTRY }}
$ cat t.sh
#!/usr/bin/env bash
eval "$(gitlab-vars -p XXXXX)"
envtemplate -i tmpl > tmpl.out
$ ls
tmpl t.sh
$ bash t.sh
$ cat tmpl.out
registry.gitlab.com