Travis CI environment variables with Gradle properties

為{幸葍}努か 提交于 2019-12-03 16:10:50

问题


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

Which is used in my build.gradle:

uploadArchives {   
    //more     
    repository(url: sonatypeRepo) {
        // more
    }
    //more
}

Of course locally it works. In travis I have added the variable under settings so I see the build log:

Setting environment variables from repository settings
$ export sonatypeRepo=[secure]

And it fails like:

FAILURE: Build failed with an exception.
* Where:
Build file '/home/travis/build/Diolor/Swipecards/library/build.gradle' line: 49
* What went wrong:
A problem occurred evaluating project ':library'.
> No such property: sonatypeRepo for class: org.gradle.api.publication.maven.internal.ant.DefaultGroovyMavenDeployer

How can I use the Travis' env variable as a Grable property but also have the local build as it?


回答1:


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



来源:https://stackoverflow.com/questions/26023884/travis-ci-environment-variables-with-gradle-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!