Does anyone know how to check if an environmental ...
# android
f
Does anyone know how to check if an environmental variables is empty in gradle ?? Ie APP_NAME I want to check if an empty string is sent back from the pipeline?
m
Use
System.getenv("APP_NAME")
f
Thanks I know how to get an environmental variables I want to check is it an empty string
m
if you have the gradle file in groovy you can do:
Copy code
if (!System.getenv("APP_NAME")?.trim()) {
    //here if null or empty
}
if you have it in kts, you can just use any kotlin function…
you can also check the groovy String property
allWhitespace
e
https://docs.gradle.org/current/javadoc/org/gradle/api/provider/ProviderFactory.html#environmentVariable-java.lang.String- you'll want to use this instead of
System.env
for Gradle Instant Execution/Configuration Caching