从
MySQL DataBase Plugin文档中可以看到包含MySQL的jdbc驱动程序:
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.
更具体地说,此插件的实际最新版本(1.1)包含连接器版本5.1.38:
Version 1.1 (May 21, 2016) mysql-connector version 5.1.38
因此,为了使驱动程序可用,您必须强制驱动程序进行注册.
为此,请在代码中实例化连接之前使用Class.forName(“com.mysql.jdbc.Driver”):
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()
}
更新:
为了在Jenkins管道groovy脚本中提供JDBC连接器类,您需要将DataBase plugin更新为上一个当前版本:
Version 1.5 (May 30, 2016) Pipeline Support