I have the following Jenkins versions and plugins:
Jenkins 2.426.3
database:247.v244b_d85f086d
database-mysql:63.va_0596d2b_1438
And here is my code to connect to mysql db:
Class.forName("com.mysql.cj.jdbc.Driver")
def url = 'jdbc:mysql://<host>:<port>/<db>'
def driver = 'com.mysql.cj.jdbc.Driver'
def sql = Sql.newInstance(url, "${username}", "${password}", driver)
It fails with No suitable driver found
.
From all the questions/answers I was reading on stackoverflow I think the reason to the failure is that mysql-connector-java driver is not in the CLASSPATH.
One of the answers suggested finding classpath from Jenkins Script Console and here is what I found:
System.getProperty("java.class.path")
Result: /usr/lib/jenkins/jenkins.war
How can I find where mysql-connector-java driver is located?
And how to add it to CLASSPATH?