Gitlab Env
A handy tool to export and import a large number of CICD environment variables.
Command usage:
go install github.com/quangthe/gitlab-env@latest
gitlab-env -h
gitlab-env export -h
gitlab-env import -h
Export Gitlab project env vars
gitlab-env export \
--gitlab-token "your-gitlab-token" \
--gitlab-host "gitlab.example.com" \
--project-id "55" \
--output-file gitlab.json
By default, the command will query the gitlab project variable with --page-number=1, --page-size=100
Tips: Use --export-all=true flag to export all project env vars.
Filter by environment scopes --env-scopes:
gitlab-env export \
--gitlab-token "your-gitlab-token" \
--gitlab-host "gitlab.example.com" \
--project-id "55" \
--env-scopes "*,dev,prod" \
--output-file gitlab.json
The gitlab.json file will look like this
[
{
"variable_type": "env_var",
"key": "FORM_URL",
"value": "jdbc:postgresql:\\/\\/shared-database:5432\\/forms",
"protected": true,
"masked": false,
"raw": true,
"environment_scope": "*",
"description": ""
},
{
"variable_type": "env_var",
"key": "POLL_URL",
"value": "jdbc:postgresql:\\/\\/shared-database:5432\\/polls",
"protected": true,
"masked": false,
"raw": true,
"environment_scope": "*",
"description": ""
}
]
Import env vars into Gitlab project
gitlab-env import \
--gitlab-token "your-gitlab-token" \
--gitlab-host "gitlab.example.com" \
--project-id "56" \
--input-file gitlab.json
By default, the import command does not filter on the Environment Scope. Use --env-scopes flag to only import env vars with selected scopes.
Example: --env-scopes "*,dev,prod" will import env vars with scope *, dev and prod.