6

I'm using liquibase via command line, i am wondering how to setup liquibase.properties file to read environment variables?

something like:

***liquibase.properties***

    driver=org.postgresql.Driver
    classpath=lib/postgresql-42.2.5.jar 

    url=${DATASOURCE_URL}
    username=${DATASOURCE_USERNAME} 
    password=${DATASOURCE_PASSWORD}

    changeLogFile=changelogs/master.yaml
Luka Špoljarić
  • 988
  • 1
  • 10
  • 23

2 Answers2

2

For the time being there is no way to use environment variables in the liquibase.properties file. This have to be implemented in the source code since Java by default won't recognize them. See https://stackoverflow.com/a/2263944/5418766 for details.

I had a similar problem trying to read the database credentials from a Bitwarden vault. I've ended up using the variables in the batch file (I'm using Windows) calling Liquibase and that worked for me.

0

here you have info about liquibase properties. However if you want to use your own properties you can put in property file parameter.property1 and then use ${property1} in your changelog as placeholder.

bilak
  • 4,526
  • 3
  • 35
  • 75
  • link is now 404 – xenoterracide Dec 17 '19 at 18:40
  • I think the page has moved to here now: https://docs.liquibase.com/workflows/liquibase-community/creating-config-properties.html – seeafish Oct 01 '20 at 16:16
  • @bilak Could you give an example of how both should look? – StealthRT Oct 22 '20 at 15:59
  • properties in `liquibase.properties` are loaded only by maven plugin :( – bilak Oct 22 '20 at 16:33
  • Hmm and it [looks like](https://github.com/liquibase/liquibase/blob/85f71ffbd23f0e4d2faa39bea6bc0244e389cd34/liquibase-core/src/main/java/liquibase/integration/commandline/Main.java#L1007) it should work even from command line so just create some repo with example and I can help you then if you need. – bilak Oct 22 '20 at 16:40
  • Thanks for the reply @bilak. Check this out https://stackoverflow.com/questions/64471150/different-paramaters-in-one-liquibase-properties-file-possible – StealthRT Oct 22 '20 at 18:16