Automatically handles authentication via environment variables \$BITBUCKET_USERNAME / \$BITBUCKER_USER and \$BITBUCKET_TOKEN (which is used as the password, your real BitBucket password isn't accepted by the BitBucket 2.0 API)
XXX: NOTE: The API is inconsistent in places, some endpoints require a trailing slash otherwise they 404, others cannot have a trailing slash otherwise they 404 the other way
# Update a repo variable (must include braces around the variable uuid but url encode the braces, omitting key still works, providing key overwrites the key field):
# List workspace variables (notice 2 inconsistencies here: for repos it's pipelines_config with a trailing slash, for workspaces it's pipelines-config with no trailing slash - the slash can result in 404):
# Create a workspace variable (see bitbucket_workspace_set_env_vars.sh for a more convenient way of adding/updating env vars, optionally in bulk):
# notice the no trailing slash otherwise 404 compared to the repo variable which requires it otherwise gets 404
# if a variable with this key already exists, will result in {\"error\": {\"message\": \"Conflict\", \"detail\": \"A variable with the key provided already exists for account...
# Update a workspace variable (must include braces around the variable uuid but url encode the braces, omitting key still works, providing key overwrites the key field):
# Get currently authenticated user (unfortunately this is less useful than with GitHub / GitLab APIs since you can't use a standard OAuth2 authentication with just the bearer token, and must specify a username to authenticate to the API in the first place):
Placeholders are replaced if the following information is available in environment variables or can be inferred from the local git repo remote urls. The tokens for replacement can be given in the form {token}, <token>, :token
\$BITBUCKET_USERNAME / \$BITBUCKET_USER: owner, username, user
the local repo name of the current directory: repo
echo"WARNING: \$BITBUCKET_USERNAME / \$BITBUCKET_USER not specified, and failed to determine from local remote url, will end up using your environment's default \$USERNAME / \$USER which may not be the right BitBucket username and can lead to authentication failures - recommend you set \$BITBUCKET_USERNAME explicitly" >&2