Connector/J MySQL driver in Jenkins Script Console / Scriptler Connector/J MySQL driver in Jenkins Script Console / Scriptler jenkins jenkins

Connector/J MySQL driver in Jenkins Script Console / Scriptler


Finaly i figured out how to use MySQL JDBC driver with Scriptler:

  1. Find out the default JAVA classpath dirs (run in Jenkins Script Console):

println System.getProperty("java.ext.dirs")

/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext:/usr/java/packages/lib/ext

  1. Download an add mysql-connector-java-*.jar to default Java classpath:

cp mysql-connector-java-*.jar /usr/java/packages/lib/ext/

  1. Restart Jenkins

Jenkins jobs and Scriptler / Groovy scripts should now work without any additional parameter like CLASSPATH.


Modifying the Jenkins classLoader should also work:

this.class.classLoader.addURL(new URL("file://${System.getProperty('user.home')}/plugins/database-mysql/WEB-INF/lib/mysql-connector-java-5.1.21.jar"))import groovy.sql.Sqlsomeapp = '[A-Z]+SOME_APP[0-9]*'someenv = 'Production'somestatus = '1'def sql = Sql.newInstance("jdbc:mysql://foo.com/somedb", "user", "pass", "com.mysql.jdbc.Driver")query = "SELECT somefield FROM sometable WHERE somefield REGEXP '$somevar' AND environment='$someenv' AND status='$somestatus'"def result = sql.rows(query).collect{ it.name }.sort{ it.find(/\d+$/) as int }sql.close()return result