-
New Feature
-
Resolution: Unresolved
-
Minor
-
None
Hi,
Me and my team had to extend the plugin by providing a new choice provider, based on the column of a particular table in a database.
As a consequence, we've created a new DbChoiceListProvider that reads a particular column, based on the plugin configuration (JDBC URL, db username, db password, class of the driver, name of the table, name of the column in which values will be read...).
Feel free to look at the provided screenshot.
Note that you can also configure a "fallback file", i.e. a file which contains multiple values (one per line) and that is read by the plugin if the database is not accessible, for any reason.
If you're OK with that, we're ready to contribute it. Of course we can discuss it if you think some improvements are required.
Looking forward to hearing from you.
Regards,
Thibault.
- is related to
-
JENKINS-28736 DB Based choice provider
-
- Open
-
Is this available anywhere? I don't see such a fork on GitHub...
I'm trying to do a very similar thing, but even less ambitious - have my Groovy script read from a database (hard-coded table, column, etc.). But it is not working due to class loader issues – i have a jar file with the sqlite driver in it, but I sure can't get it to be recognized by the Groovy...
import groovy.sql.Sql
//def jc = jenkins.getPluginManager().uberClassLoader;
def jc = this.getClass().getClassLoader()
def furl = new File("/vagrant/lib/sqlite-jdbc-3.8.7.jar").toURL()
jc.addURL(furl)
def cc = Class.forName('org.sqlite.JDBC', true, jc)
java.sql.DriverManager.registerDriver(cc.newInstance())
def props = new java.util.Properties()
def sql = new Sql(java.sql.DriverManager.getConnection('jdbc:sqlite:databasefile.sqlite', props))
Results in:
Failed to execute script
java.sql.SQLException: No suitable driver found for jdbc:sqlite:databasefile.sqlite
at java.sql.DriverManager.getConnection(DriverManager.java:596)
at java.sql.DriverManager.getConnection(DriverManager.java:187)
at java_sql_DriverManager$getConnection.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at Script1.run(Script1.groovy:9)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:580)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:618)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:589)
btw - you see in the commented out code, i tried using the class loader of the jenkins - unfortunately it wasn't a WebappClassLoader or NetworkClassLoader, so there didn't seem to be a way to add the jar file to it.