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/83eccabf-a68f-d756-1a89-505d6337e13a%40perforce.com.
For more options, visit https://groups.google.com/d/optout.