Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run custom database scripts in 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.

like image 611
John Doe Avatar asked Jun 25 '12 07:06

John Doe


2 Answers

You have two major options:

  • use the Execute shell or Execute Windows batch command build steps

  • 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'

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

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.

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.

like image 81
Jens Schauder Avatar answered Oct 19 '22 06:10

Jens Schauder


Out of the box, there is no database plugin or job in Jenkins.

The easiest way to do this would be a Ant task. There is native support for ant tasks in Jenkins. Checkout the SQLTask of Ant.

like image 3
i.am.michiel Avatar answered Oct 19 '22 07:10

i.am.michiel