我目前正在研究一些將liquibase更改應用於數據庫的ant。 我希望能夠處理從liquibase updateDatabase任務中獲得的錯誤。這是我現在在我的構建文件中(記住我現在工作正常,我只需要能夠處理我可能從運行liquibase得到的錯誤)。我如何處理我從liquibase updateDatabase ant任務獲得的錯誤
<target name="update_db" depends="prepare">
<taskdef resource="liquibasetasks.properties">
<classpath refid="classpath"/>
</taskdef>
<updateDatabase
changeLogFile="${db.changelog.file}"
driver="${database.driver}"
url="jdbc:mysql://localhost/${db.name}"
username="${user}"
password="${password}"
promptOnNonLocalDatabase="not local database"
dropFirst="false"
classpathref="classpath"
/>
</target>
目前,當我得到一個錯誤,我得到一些與此類似(從一個情況下,我創建演示):
BUILD FAILED
MYPATH\build.xml:15: The following error occurred while executing this line:
MYPATH\\build.xml:117: liquibase.exception.MigrationFailedException: Migration failed
for change set PATH/2.20.9/tables.xml::FFP-1384::AUSER:
Reason: liquibase.exception.DatabaseException: Error executing SQL ALTER TABLE
test.widget ADD full_screen BIT(1) DEFAULT 0: Duplicate column name 'full_screen'
.............. and a the wall of text continues
理想情況下,我想能夠得到的返回碼(而比這塊文本)從liquibase到螞蟻,然後根據那個做一些事情,如:
<echo message="this failed because ${reason}"/>
但不限於此。
有沒有辦法讓我從liquibase獲取返回碼?我最好的猜測是,類似於ant exec任務,默認情況下,返回碼被忽略,我希望有一些方法可以讓我瞭解它。歡迎任何建議。
編輯:依稀類似的問題https://stackoverflow.com/questions/17856564/liquibase-3-0-2-logging-to-error-console
HTTP://www.liquibase .org/documentation/ant/updatedatabase_ant_task.html看起來沒有辦法得到返回碼 - 任務沒有實現它。 exec可以得到返回碼的原因是它執行一個外部程序 - 這意味着一個新的進程。對於常見的Ant任務,它只是一段代碼,在當前Ant構建的相同進程中執行,因此無法獲得任何「返回代碼」。對於ur實例,如果任務通過套接字連接到數據庫,或直接打開數據庫,則不會有新進程,因此不會返回代碼。 – coolcfan
是的,似乎是這樣,我現在已經利用了至少讓我處理失敗的ant contrib try catch任務。 – Danny