environment-variablesflyway

Pass environment variables to Flyway config


I've been searching ages for this, so I'm going to answer this question myself...

How do I use and reference system environment variables in a flyway configuration file?


Solution

  • You have to add the env. namespace before the envar name, and wrap it in ${env.MY_ENVAR_NAME}.

    Example:

    Setting up an exemplary environment variable, e.g. in bash

    export MY_ENVAR_KEY=MY_ENVAR_VALUE
    

    Using the environment variable in the flyway.toml

    ...
    
    [environments.dev]
    url = "jdbc:snowflake://something.snowflakecomputing.com/?db=SOME_DB&warehouse=SOME_WH&role=SOME_ROLED&schema=SOME_SCHEMA&authenticator=snowflake_jwt&private_key_file=path/to/snowflake.p8&jdbc_query_result_format=json&private_key_file_pwd=${env.MY_ENVAR_KEY}"
    
    ...