Travis CI environment variables with Gradle properties

前端 未结 2 2161
攒了一身酷
攒了一身酷 2021-02-07 11:26

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


        
相关标签:
2条回答
  • 2021-02-07 12:09

    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...

    0 讨论(0)
  • 2021-02-07 12:20

    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.

    0 讨论(0)
提交回复
热议问题