Read OS environment variables on application.yml

1,286 views
Skip to first unread message

Rafael Felini

unread,
Apr 8, 2015, 8:53:16 AM4/8/15
to grails-de...@googlegroups.com
Hi everyone!

    Does anyone knows what I have to do to read an OS environment variables on application.yml?

    I need to read some vars like database user, password, url and ci build number from OS environment variables.

    As Grails is based on Spring Boot, reading through Spring Boot docs http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config it reads from OS environment variables, but apparently it does not apply to Grails. 

    My application.yml is like this snippet:    
    production:
        dataSource:
            driverClassName: com.mysql.jdbc.Driver
            dialect: org.hibernate.dialect.MySQL5InnoDBDialect
            dbCreate: update
            url: ${DB_JDBC_URL}
            username: ${DB_USERNAME}
            password: ${DB_PASSWORD}

Thanks,
Rafael

Lucas Videla

unread,
May 1, 2015, 10:07:49 PM5/1/15
to grails-de...@googlegroups.com
Hey Rafael... did you get any responses or workarounds?
I have the same question here :)

Thanks!

Rafael Felini

unread,
May 4, 2015, 8:17:38 AM5/4/15
to grails-de...@googlegroups.com
Hi Lucas!

I created a application.groovy file and put all configs that comes from os env var there. I don't like much doing this, but works for now.


--
You received this message because you are subscribed to a topic in the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grails-dev-discuss/Zxv6EzyrRGY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grails-dev-disc...@googlegroups.com.
To post to this group, send email to grails-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/09636ac1-6bcc-463c-b969-fd7c7c54e6d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Hepner

unread,
Oct 19, 2015, 2:57:05 PM10/19/15
to grails-de...@googlegroups.com
I think you just need quotes. Here's what I have

production:
dataSource:
url: "${JDBC_CONNECTION_STRING}"
driverClassName: com.mysql.jdbc.Driver
username: "${DB_USER}"
password: "${DB_PASS}"


I found the answer here:

http://se.ecologic.ch/?p=28



--
View this message in context: http://grails.1312388.n4.nabble.com/Read-OS-environment-variables-on-application-yml-tp4659099p4659827.html
Sent from the Grails Dev Discuss mailing list archive at Nabble.com.

Daniel Leahy

unread,
Dec 3, 2018, 4:11:49 PM12/3/18
to Grails Dev Discuss
Hi, 
       link posted is not accessible

Regards,
               Daniel.
Reply all
Reply to author
Forward
0 new messages