Reputation: 1636
I am deploying my Play! 2.1 application on Cloudbees.
I have in my application.conf:
# Database configuration
# ~~~~~
db.default.driver=com.mysql.jdbc.Driver
db.default.url=${MYSQL_URL_DB}
db.default.user=${MYSQL_USERNAME_DB}
db.default.password=${MYSQL_PASSWORD_DB}
I defined those values in Cloudbees configuration:
$ bees config:list -a myself/my-app
Application Parameters:
proxyBuffering=false
MYSQL_URL_DB=jdbc:cloudbees://my-app
MYSQL_USERNAME_DB=my-app
MYSQL_PASSWORD_DB=yummy
Runtime Parameters:
java_version=1.7
I publish my app using git (git push cloudbees cloudbees:master
) which triggers Jenkins. But when it comes to deploying application, I get in Jenkins logs:
[error] (compile:compile) com.typesafe.config.ConfigException$UnresolvedSubstitution: conf/application.conf: 16: Could not resolve substitution to a value: ${MYSQL_PASSWORD_DB}
Is there anything else to do to make Jenkins aware of the configuration? Did I misunderstand something?
Thanks for your help!
Alban
Upvotes: 2
Views: 4120
Reputation: 1266
You can add "?" to the beginning, so it will be treated as an override.
db.default.url=${?MYSQL_URL_DB}
You can also handle fallback situations with this approach, if you like.
db.default.url=mysql://fallback_url
db.default.url=${?MYSQL_URL_DB}
If MYSQL_URL_DB does not exist, fallback_url will be used.
Upvotes: 7
Reputation: 19478
I use a config like this:
https://github.com/CloudBees-community/play2-clickstart/blob/master/conf/application.conf
and a build command like this:
java -Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=384M -jar /opt/sbt/sbt-launch-0.11.3-2.jar -Dsbt.log.noformat=true clean compile test dist
And it does not worry about the missing environment variables. My guess is that there is a scala macro or something that triggers the compiler to resolve those variables. Adding them in is fine.
I have amended the clickstart to set default values in case they are needed.
Upvotes: 1
Reputation: 2633
This configuration is injected at runtime, not build time. You have to find a way to make the sbt build ignore unresolved substitution. It seems a possible workaround is to set MYSQL_URL_DB=foo, etc as build environment variables, so that the check don't break, as they won't be actually injected in your configuration
Upvotes: 1