How can I reference a Travis secure variable in my build.gradle?

ataulm

One of my project dependencies sits on a private Bintray repo, which requires a username and password to access. Locally, I have these set in my gradle.properties:

bintrayUsername=<myUserName>
bintrayPassword=<myPass>

This works (locally), where hasProperty(X) resolves true and it 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'
        }
    }
}

On Travis, I use secure variables so I don't have to expose these values in my public repo, but with the aim of being able to build directly from my public repo. When the build 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 unsure how to reference the exported environment variables in my build.gradle such that they would be found.

I've checked this answer which doesn't seem to work (as above), as well as this comment which results in the same build failure.

The series of commits I've tried can be seen here, with the latest: https://github.com/ataulm/wutson/commit/9331b8d91b4acf11fd3e286ff8ba1a24ed527177

Mark Vieira

The error is a result of your ternary statement attempting to evaluate bintrayUsername as part of the condition.

The hasProperty() method takes a String argument so you should use hasProperty('bintrayUsername'), instead of hasProperty(bintrayUsername). Doing the latter will attempt to evaluate a property that may not exist, leading to the MissingPropertyException.

Simply remember that trying to evaluate any symbol that doesn't exist will typically result in a MissingPropertyException.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I reference an environment variable in TFS build configuration?

How can I have Travis-CI build my electron app for multiple OSes in parallel?

How can I use an environment variable to specify branches to build in .travis.yml?

Can I build all my gradle build flavors at once?

How can I get clean Gradle output on Travis CI?

How do I use Vite to build asset file that I can reference in the <head> of my pages?

How can I determine what dependencies I need in the gradle build file for my Android project

How do I set an environment variable in Android Studio before it runs my gradle build

How can I run a script as part of a Travis CI build?

How can I build a python project with osx environment on travis

How can I build Visual Studio 2019 projects on Travis CI?

How can I use a secure file in a CircleCI build?

How can I build a secure timer based button?

How can I build a Gradle plugin with Maven

How to build on travis-ci with gradle and cobertura

How can I build my Gradle project using a Windows JDK from Ubuntu on Windows?

How can I share build code script for all my gradle projects (not just subprojects)

Can I get a reference to the current `ICakeContext` in my Cake build script?

How can I secure the cloud database for my mobile app?

How can I make my WiFi hotspot secure?

How can I secure my SSH commands to a remote server in Laravel?

How can I secure my Ubuntu 13.04 to prevent network attacks?

How can I insure that my retrieval of secrets is secure?

How can I make sure my power line network is secure?

How can I secure my Firestore database agains unwanted access?

How can I confirm my AWS MySQL connection is secure?

How can I secure my domain-driven types with TypeScript?

How can I make my domain secure, and invisible?

How can I secure the use of my dll by other applications