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

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.