Skip to content

Instantly share code, notes, and snippets.

@baz8080
Created October 15, 2016 13:07
Show Gist options
  • Save baz8080/87d8840fede76b1aeef6f4ab9ca98722 to your computer and use it in GitHub Desktop.
Save baz8080/87d8840fede76b1aeef6f4ab9ca98722 to your computer and use it in GitHub Desktop.
Gets a environment variable, or falls back to a property
/**
* Looks for the specified configuration key in this order:
*
* <ol>
* <li>system environment</li>
* <li>project properties</li>
* </ol>
*
* If it isn't found, then the empty string is returned. This stops the gradlew from failing until
* it actually needs those values.
*
* @param keyName The key to look for
* @return The value or the empty string if not found
*/
def getConfigurationParameter(String keyName) {
return System.getenv(keyName) ?:
rootProject.hasProperty(keyName) ? rootProject.properties[keyName] : ''
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment