在Jenkins中运行自定义数据库脚本

问题描述:

到目前为止,我已经看到了不同的选项和工作在Jenkins与建设过程有关。我想知道是否有一种方法来创建一个连接到数据库并运行脚本的作业,这将执行一些操作。也许,Jenkins可以运行一个脚本文件或只是存储一些操作运行。提前致谢。

So far I've seen different options and jobs in Jenkins that were related to the build process. I wonder if there is a way to create a job that would connect to the database and run a script, that would perform some actions. Maybe, Jenkins could run a script file or just store some actions to run. Thanks in advance.

您有两个主要选项:


  • 使用执行shell 执行Windows批处理命令构建步骤

一个基于java的工具,如liquibase,ant任务,maven插件或更多。你甚至可以使它成为JUnit测试的一部分。考虑搜索数据库迁移java

use a java based tool like liquibase, ant tasks, maven plugin or many more. You might even make it part of JUnit tests. Consider searching for 'database migration java'

这些是正确的解决方案取决于build:

Which of those is the 'correct' solution depends on the purpose of the build:

你需要数据库进行一些测试吗?那么你可能应该使用基于java的解决方案,因为它是平台无关的,并且很可能在任何操作系统上工作。

Do you need the databases for some tests? Then you probably should go with a java based solution, because it is platform independent and will most likely work on any OS.

你想实际测试数据库脚本你把它们交给管理员进行部署?然后你可能想使用管理员要使用的确切的工具,并在管理员使用的操作系统上执行它。很可能他们不是很热衷于使用基于java的工具。

Do you want to actually test the database scripts before you hand them of to the admins for deployment? Then you probably want use the exact tool the admins going to use and execute it on the OS the admins use. Most likely they aren't very keen to use a java based tool for the job.