Skip to content

Instantly share code, notes, and snippets.

@douglascayers
Created September 28, 2022 19:22
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 douglascayers/3d1f30a56ebfb74161debc45e87a17e0 to your computer and use it in GitHub Desktop.
Save douglascayers/3d1f30a56ebfb74161debc45e87a17e0 to your computer and use it in GitHub Desktop.
Sync Heroku config vars to CircleCI project env vars
#!/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