Disclaimer: This is not an encouragement to use BitBucket. This is only here to help the poor people who are stuck with it.
The following JavaScript functions can be used to extract the environment variables for a BitBucket deployment into a shell script which sets the environment variables locally.
This is helpful for when you want to test something locally without manually having to copy and paste 50 environment variables.
/**
* Get the deployment variables for a given BitBucket deployment, and return them in a dictionary.
*