How can I use travis-ci env variables as Gradle\'s properties?
I locally have my gradle.properties under the gradle path having:
sonatypeRepo = abcd
I just stumbled on this too.
This is how I got it to work:
In my build.gradle
def uzer = hasProperty('blahUser') ? blahUser : System.getenv('blahUser')
def creds = hasProperty('blahPwd') ? blahPwd : System.getenv('blahPwd')
In my $HOME/.gradle/gradle.properties
blahUser=batman
blahPwd=eatsworms
So I needed this for travis-ci -- which I don't think has a notion of a $HOME/.gradle/gradle.properties But you can add environment variables to .travis.yml.
Basically, as previously mentioned, if the property is 'there'; gradle uses it, otherwise asks the environment for it. In my case the 'hasProperty()' check was needed so travis wouldn't generate a property not found exception.....
hth...
Below an example to define a project property, not a local variable, if it is not defined, by getting the value from the Environment.
project.ext {
if (! project.hasProperty('some_prop')) {
some_prop = System.getenv('some_prop')
}
}
I wanted a project property so I can use it also to set the PWs in my spring-boot YAML file... both locally and in CI.