Just completing the loop in case anyone else is looking into this. My
colleague tried my solution in his instance and it didn't work.
After doing some more archeology I realized that I at one point printed
out the system java.ext.dirs, which included
/usr/java/packages/lib/ext. I then created that path and copied the
mysql-connector-java-5.1.38.jar there. After a restart of Jenkins I
could now import and use groovy.sql.Sql quite happily, not just on the
master but on remote nodes.
So while this functions, it seems hard to consider this as a working
production solution.
Pete
On 1/16/2017 10:47 AM, Peter McNab wrote:
Oddly enough, after sending this I found I *was* able to skip the
extra wrapper and make this work.
I swear I had tried that earlier with no luck.
(As it happens, I need to use the wrapper for other purposes)
Pete
On 1/16/2017 10:44 AM, Peter McNab wrote:
On 1/12/2017 1:53 PM, Peter McNab wrote:
Has anyone got a working solution for running SQL queries from a
pipeline script (specifically MySQL?)
Pete
Answering my own post...I've found a method that functions, although
it's not ideal.
1) Install the "Pipeline Classpath Step Plugin
2) Make my pipeline script (from SCM) be essentially a small wrapper:
pipelinePath = <workspacedir>
addToClasspath pipelinePath
node('master') {
load "${pipelinePath}/Jenkinsfile"
}
3) In the Jenkinsfile, add "import groovy.sql.Sql"
4) Add this into the Jenkinsfile:
stage ('SQL Test') {
node('remote_node') {
def sql = Sql.newInstance("jdbc:mysql://DBHOST/DBSCHEMA",
"DBUSER", "DBPASSWORD", "com.mysql.jdbc.Driver")
query = "SELECT * from myTable"
println sql.rows(query)
sql.close()
}
}
5) Note that you will need to whitelist the various Sql methods you
call using the script security plugin
--
You received this message because you are subscribed to the Google Groups "Jenkins
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/13d06493-11a2-e842-0978-82e003480956%40perforce.com.
For more options, visit https://groups.google.com/d/optout.