Skip to content

Instantly share code, notes, and snippets.

@danielgomezrico
Last active July 27, 2021 12:37
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save danielgomezrico/461bf74a24dd5efd28abef1bebc0f05d to your computer and use it in GitHub Desktop.
Save danielgomezrico/461bf74a24dd5efd28abef1bebc0f05d to your computer and use it in GitHub Desktop.
Gradle / Bash - copy all env variables to app/gradle.properties (used to copy secret env vars from travis or circle CI to build android projects)
#!/usr/bin/env bash
#
# Copy env variables to app module gradle properties file
#
set +x // dont print the next lines on run script
printenv | tr ' ' '\n' > app/gradle.properties
set -x
@chriscm2006
Copy link

For those considering this solution, I found a much simpler alternative that works in some environments. Environment variables that start with "ORG_GRADLE_PROJECT_" are brought in as Gradle props!

@bsameh
Copy link

bsameh commented Dec 9, 2018

For those considering this solution, I found a much simpler alternative that works in some environments. Environment variables that start with "ORG_GRADLE_PROJECT_" are brought in as Gradle props!

@chriscm2006 This is a lot cleaner, thank you!

  1. This doesn't require dynamically generating a gradle.properties file.
  2. Only relevant variables (those prefixed with ORG_GRADLE_PROJECT_) are considered by Gradle, as opposed to printing all variables into gradle.properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment