How can I refer to the protected Travis variable in my build.gradle?

One of my dependencies between projects is on a private Bintray repository that requires a username and password. Locally, I have these settings in my gradle.properties:

bintrayUsername=<myUserName>
bintrayPassword=<myPass>

This works (locally), where it hasProperty(X)resolves to true and uses this property:

allprojects {
    repositories {
        jcenter()

        def mahBintrayUsername = hasProperty(bintrayUsername) ? bintrayUsername : System.getenv('bintrayUsername')
        def mahBintrayPassword = hasProperty(bintrayPassword) ? bintrayPassword : System.getenv('bintrayPassword')


        maven {
            credentials {
                username mahBintrayUsername
                password mahBintrayPassword
            }
            url 'http://dl.bintray.com/my-repo-org/maven-private'
        }
    }
}

In Travis, I use protected variables , so I don’t need to disclose these values ​​in my public repo, but with the goal of being able to build directly from my public repo. When the assembly starts, you can see that the variables are exported:

Setting environment variables from .travis.yml
$ export bintrayUsername=[secure]
$ export bintrayPassword=[secure]
$ export TERM=dumb

...

FAILURE: Build failed with an exception.
* Where:
Build file '/home/travis/build/ataulm/wutson/build.gradle' line: 15
* What went wrong:
A problem occurred evaluating root project 'wutson'.
> Could not find property 'bintrayUsername' on repository container.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED

I'm not sure how to reference the exported environment variables in mine build.gradleso that they are found.

, , , ( ), , .

, , , : https://github.com/ataulm/wutson/commit/9331b8d91b4acf11fd3e286ff8ba1a24ed527177

+4
1

, bintrayUsername .

hasProperty() String, hasProperty('bintrayUsername') hasProperty(bintrayUsername). , , MissingPropertyException.

, , , MissingPropertyException.

+3

Source: https://habr.com/ru/post/1569361/


All Articles