Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-24274

New DB-based choice provider

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      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.

        Attachments

          Issue Links

            Activity

            Hide
            java1guy Mark Chance added a comment - - edited

            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.

            Show
            java1guy Mark Chance added a comment - - edited 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.
            Hide
            kinow Bruno P. Kinoshita added a comment -

            I'm interested in taking a look at the implementation too, please

            We are working on a new plug-in that is related to the Extensible Choice Parameter, but that supports cascading changes from other parameters - https://wiki.jenkins-ci.org/display/JENKINS/Uno+Choice+Plugin

            There is an open issue there that links to this issue too https://github.com/biouno/uno-choice-plugin/issues/63

            We are looking for ways to integrate a similar parameter type there too, so if anyone is interested in jumping in and giving a try too, you're more than welcome.

            Thanks!

            Show
            kinow Bruno P. Kinoshita added a comment - I'm interested in taking a look at the implementation too, please We are working on a new plug-in that is related to the Extensible Choice Parameter, but that supports cascading changes from other parameters - https://wiki.jenkins-ci.org/display/JENKINS/Uno+Choice+Plugin There is an open issue there that links to this issue too https://github.com/biouno/uno-choice-plugin/issues/63 We are looking for ways to integrate a similar parameter type there too, so if anyone is interested in jumping in and giving a try too, you're more than welcome. Thanks!
            Hide
            tduchateau Thibault Duchateau added a comment -

            Hi,

            Sorry for the late reply :-/

            Here are the items I wanted to check before submitting the PR:

            Waiting for any PR to be submitted, I'll fork https://github.com/jenkinsci/extensible-choice-parameter-plugin in the next days and push my commits.
            I'll keep you posted.

            Regards,
            Thibault

            Waiting for help, I'll fork the

            Show
            tduchateau Thibault Duchateau added a comment - Hi, Sorry for the late reply :-/ Here are the items I wanted to check before submitting the PR: integrate the Database plugin ( https://wiki.jenkins-ci.org/display/JENKINS/Database+Plugin ) in order to avoid putting the driver JAR manually in the classpath. But with no success. I asked for help some months ago here: http://jenkins-ci.361315.n4.nabble.com/Extending-a-plugin-using-the-Database-Plugin-td4715530.html write some tests but I didn't had time to take a look at how to write tests for Jenkins Waiting for any PR to be submitted, I'll fork https://github.com/jenkinsci/extensible-choice-parameter-plugin in the next days and push my commits. I'll keep you posted. Regards, Thibault Waiting for help, I'll fork the
            Show
            tduchateau Thibault Duchateau added a comment - PR submitted: https://github.com/jenkinsci/extensible-choice-parameter-plugin/pull/8
            Hide
            kinow Bruno P. Kinoshita added a comment -

            Triaging issues for active-choices-plugin today and found this issue linked to another one (JENKINS-28736). Will look at implementing it for active-choices, using the pull request as reference. If there's nothing that break compatibility, and it makes sense to add this parameter type, this should be shipped with active-choices-plugin 1.5.4 (probably in one or two weeks).

            Show
            kinow Bruno P. Kinoshita added a comment - Triaging issues for active-choices-plugin today and found this issue linked to another one ( JENKINS-28736 ). Will look at implementing it for active-choices, using the pull request as reference. If there's nothing that break compatibility, and it makes sense to add this parameter type, this should be shipped with active-choices-plugin 1.5.4 (probably in one or two weeks).

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              tduchateau Thibault Duchateau
              Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated: