How to add a JDBC driver to a Jenkins pipeline?

て烟熏妆下的殇ゞ 提交于 2019-12-04 05:49:48

From the MySQL DataBase Plugin documentation you can see that jdbc drivers for MySQL are included:

Note that MySQL JDBC driver is under GPLv2 with FOSS exception. This plugin by itself qualifies under the FOSS exception, but if you are redistributing this plugin, please do check the license terms. Drizzle(+MySQL) Database Plugin is available as an alternative to this plugin, and that one is under the BSD license.

More concretely the actual last version (1.1) for this plugin contains connector version 5.1.38:

Version 1.1 (May 21, 2016) mysql-connector version 5.1.38

So probably in order to have the driver available you have to force the driver to be registered.

To do so use Class.forName("com.mysql.jdbc.Driver") before instantiate the connection in your code:

import groovy.sql.Sql
node{
    Class.forName("com.mysql.jdbc.Driver")
    def sql = Sql.newInstance("jdbc:mysql://mysql:3306/test_db", "user","passwd", "com.mysql.jdbc.Driver")
    def rows = sql.execute "select count(*) from test_table;"
    echo rows.dump()
}

UPDATE:

In order to has the JDBC connector classes available in the Jenkins pipeline groovy scripts you need to update the DataBase plugin to last currently version:

Version 1.5 (May 30, 2016) Pipeline Support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!