Created
September 28, 2022 19:22
-
-
Save douglascayers/3d1f30a56ebfb74161debc45e87a17e0 to your computer and use it in GitHub Desktop.
Sync Heroku config vars to CircleCI project env vars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
if [ -z "${CIRCLECI_API_TOKEN}" ]; then | |
echo "Missing required environment variable: CIRCLECI_API_TOKEN" | |
echo "You can create one at https://app.circleci.com/settings/user/tokens" | |
fi | |
ORG_NAME="your-gh-org" | |
REPO_NAME="your-gh-repo" | |
PROJECT_SLUG="github/${ORG_NAME}/${REPO_NAME}" | |
HEROKU_APP="your-heroku-app" | |
# List of variables to copy from Heroku to CircleCI | |
# to be stored in the project environment variables. | |
# Variables that are available in other CircleCI contexts | |
# don't need to be listed here, but duplicating here isn't a problem either. | |
VARS=( | |
AWS_REGION | |
SALESFORCE_CLIENT_ID | |
SALESFORCE_CLIENT_SECRET | |
SALESFORCE_PASSWORD | |
SALESFORCE_URL | |
SALESFORCE_USERNAME | |
TRAILHEAD_ENV | |
) | |
for VAR in "${VARS[@]}"; do | |
ENV_KEY="${VAR}" | |
ENV_VAL=$(heroku config:get --app=${HEROKU_APP} ${ENV_KEY}) | |
RESULT=$( | |
curl --silent --show-error --location \ | |
-X POST \ | |
-H "Circle-Token: ${CIRCLECI_API_TOKEN}" \ | |
-H "Content-Type: application/json" \ | |
-d '{ "name": "'"${ENV_KEY}"'", "value": "'"${ENV_VAL}"'" }' \ | |
"https://circleci.com/api/v2/project/${PROJECT_SLUG}/envvar" | |
) | |
echo $RESULT | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment