Drop tables through Jenkins

1.2k views Asked by At

I am using drop command to delete multiple tables in MySQL Database.

I want to fire drop command through Jenkins for these tables.

How can I connect Jenkins with DB to fire Drop commands?

1

There are 1 answers

1
mikeb On

I would write a Groovy script to do what you want to (i.e. drop tables):

Connecting to MySQL using Groovy

Then, I would install a Groovy Jenkins plugin and call that Groovy script to do the drop whenever you want to - post build is one opportunity:

https://wiki.jenkins.io/display/JENKINS/Groovy+Postbuild+Plugin

There are other ways, but this is how I would do it.

EDIT Since you asked for how to drop table in Groovy - try something like this:

import groovy.sql.Sql

def sql = Sql.newInstance("jdbc:mysql://localhost:3306/test", "root","sms003", "com.mysql.jdbc.Driver")

//Drop table if it already exists
sql.execute('drop TABLE users')