Managing Project and Group level Environment Variables

git-vars package

Managing Project and Group level Environment Variables

Important Limitation for Nested Groups

git-vars 0.0.6 truncates a nested namespace to its top-level group when it builds the group API endpoint. Do not use its group-scoped pull or push commands for git.nrw subgroup projects because they can read from or modify the wrong group.

For group variables, use the GitLab UI or a reviewed API call that identifies the complete numeric group ID. Make changes in a disposable group first and keep an explicit backup.

Separating Project and Group Variables

If you export variables through a verified method, keep project-level and group-level variables in separate protected files outside the repository. Never commit either file.

The following Python example shows how separate project and group files can be read after you have created them safely:

from environs import Env

# Initialize environs
env = Env()
env.read_env('../ci-vars/project.env')
env.read_env('../ci-vars/group.env')

# Access environment variables
database_url = env('DATABASE_URL')
api_key = env('API_KEY')
global_api_key = env('GLOBAL_API_KEY')
sentry_dsn = env('SENTRY_DSN')

print("DATABASE_URL:", database_url)
print("API_KEY:", api_key)
print("GLOBAL_API_KEY:", global_api_key)
print("SENTRY_DSN:", sentry_dsn)

Optional feedback