Skip to content

Instantly share code, notes, and snippets.

@matchaxnb
Created August 3, 2023 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matchaxnb/0a1ac7ea256fc3c2745166413fe8ad1e to your computer and use it in GitHub Desktop.
Save matchaxnb/0a1ac7ea256fc3c2745166413fe8ad1e to your computer and use it in GitHub Desktop.
GitLab JSON variables to POSIX shell variables
#!/usr/bin/env python
"""jsontovars.py: parse GitLab API /projects/<id>/variables endpoint and export as shell variables"""
import sys
import json
data = json.load(sys.stdin)
for item in data:
if item['variable_type'] != 'env_var':
continue
print(f"""export {item['key']}="{item['value']}" """)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment