Allow upload of gradle.properties for Android builds

See: http://www.kiodev.com/circle-ci-and-gradle-properties/

 

"The last CI tool I used (Jenkins) allowed developers to create and upload a gradle.properties file to their account, and this file was referenced by their Jenkins builds.  This file was stored in a secure location, so credentials were kept safe.  Unfortunately, Circle CI doesn’t have a similar configuration option to just upload your file.  Instead, Circle CI requires you to store credentials and other secret information as environment variables for your project.

So, I just needed to figure out a way to link the environment settings on Circle CI with the values in environment variables. I really didn’t want to add logic in my build.gradle file to look in different places depending on if it is a local or CI build.  I just wanted my project to always look for credentials in the same spot; it shouldn’t have to know if it is a CI build or not. More importantly, I’d like my CI build to be as close to my local build as possible, because consistable builds are important! 

I decided I could just set the environment variables in the Circle CI GUI, and then write a shell script which would run prior to building only for CI, and copy environment variables into a gradle.properties file on the CI instance.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
}
  • Guest
  • Nov 12 2019
  • New
  • Attach files