LiquiBase - Passing Parameter From CommandLine Or Properties to Changeset XML

断了今生、忘了曾经 提交于 2020-11-29 10:45:56

问题


I am trying to pass a parameter from my update command as well as the liquibase properties file to my changeset. For some reason, it does not recognise the placeholder as a parameter but parses it as a value.

This is how I invoke the changeLog (which runs successfully):

@echo off
call Liquibase --changeLogFile=myChangeLogFile.xml update -Dparamname=value

myChangeLogFile.xml:

<changeSet author="tobi" id="preMigration" runAlways="true">
    <executeCommand executable="C:\myBatFile.bat">
        <arg value="${liquibase.properties.Dparamname}"/>
        <arg value="${liquibase.properties.url}"/>
    </executeCommand>  
</changeSet>

The script does not recognise ${liquibase.properties.Dparamname} or ${liquibase.properties.url} as placeholders.

My Liquibase.properties file has the

url:jdbc:oracle:thin:@xyz:1521:ORCL 

parameter set.

Any idea how I can access the properties or the command line parameters?

Thank you

I would appreciate your feedback.

Tobias


回答1:


Rather than using this in your changelog:

<changeSet author="tobi" id="preMigration" runAlways="true">
    <executeCommand executable="C:\myBatFile.bat">
        <arg value="${liquibase.properties.Dparamname}"/>
        <arg value="${liquibase.properties.url}"/>
    </executeCommand>  
</changeSet>

it should look more like this:

<changeSet author="tobi" id="preMigration" runAlways="true">
    <executeCommand executable="C:\myBatFile.bat">
        <arg value="${paramname}"/>
        <arg value="${url}"/>
    </executeCommand>  
</changeSet>

The -D on the command line is the standard java mechanism for setting system properties, but when accessing them you just use the property name. I am fairly certain that you don't need to use the liquibase.properties prefix either.




回答2:


I have a requirement like calling a .bat file with parameters from liquibase upgrade scripts. Also also this should run only one time like change set.

Thanks, Jagadeesh



来源:https://stackoverflow.com/questions/42368969/liquibase-passing-parameter-from-commandline-or-properties-to-changeset-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!