Skip to content

Instantly share code, notes, and snippets.

@ToroNZ
Last active August 24, 2020 06:02
Show Gist options
  • Select an option

  • Save ToroNZ/360db135525e904a90471afe4b15a258 to your computer and use it in GitHub Desktop.

Select an option

Save ToroNZ/360db135525e904a90471afe4b15a258 to your computer and use it in GitHub Desktop.
(python3) Get all ENV variables into JSON
#!/usr/bin/env python3
import os
import json
ENV_LIST = dict(os.environ.items())
VALUES = [{"key": k, "value": v, "secured": "true"} for k, v in ENV_LIST.items()]
LOCAL_VARS = json.dumps(VALUES, indent=4)
# Meant to be invoked in shell as '$ python3 env-to-json.py > local_vars.json'
print(LOCAL_VARS)
@ToroNZ
Copy link
Author

ToroNZ commented Aug 23, 2020

Primarily to be used by Bitbucket pipelines before using 'pipe'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment