Skip to content

Instantly share code, notes, and snippets.

@KioKrofovitch
Created February 16, 2016 18:52
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save KioKrofovitch/716e6a681acb33859d16 to your computer and use it in GitHub Desktop.
Save KioKrofovitch/716e6a681acb33859d16 to your computer and use it in GitHub Desktop.
#
# Circle CI & gradle.properties live in harmony
#
# Android convention is to store your API keys in a local, non-versioned
# gradle.properties file. Circle CI doesn't allow users to upload pre-populated
# gradle.properties files to store this secret information, but instaed allows
# users to store such information as environment variables.
#
# This script creates a local gradle.properties file on current the Circle CI
# instance. It then reads environment variable TEST_API_KEY_ENV_VAR which a user
# has defined in their Circle CI project settings environment variables, and
# writes this value to the Circle CI instance's gradle.properties file.
#
# You must execute this script via your circle.yml as a pre-process dependency,
# so your gradle build process has access to all variables.
#
# dependencies:
# pre:
# - source environmentSetup.sh && copyEnvVarsToGradleProperties
#!/usr/bin/env bash
function copyEnvVarsToGradleProperties {
GRADLE_PROPERTIES=$HOME"/.gradle/gradle.properties"
export GRADLE_PROPERTIES
echo "Gradle Properties should exist at $GRADLE_PROPERTIES"
if [ ! -f "$GRADLE_PROPERTIES" ]; then
echo "Gradle Properties does not exist"
echo "Creating Gradle Properties file..."
touch $GRADLE_PROPERTIES
echo "Writing TEST_API_KEY to gradle.properties..."
echo "TEST_API_KEY=$TEST_API_KEY_ENV_VAR" >> $GRADLE_PROPERTIES
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment