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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With