简体   繁体   中英

How to make the Oracle jdbc driver jar available to jenkins pipeline script on a slave

I'm trying to write a pipeline script that runs a query on an oracle db. I have a slave where I've installed the Oracle JDBC driver jar.

In global settings on the master, I've set the "Additional groovy classpath" field to the path to the driver jar on the slave.

I then ran my pipeline script, which so far is very simple:

import groovy.sql.Sql;

node ("sqlplus") {
    stage ("RUN QUERY") {
        def sql = Sql.newInstance("jdbc:oracle:thin:@...", "..", "..", "oracle.jdbc.driver.OracleDriver")
         query = "SELECT count(*) from ..."
         println sql.rows(query)
         sql.close() 
    }
}

This compiles, but it fails with "java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver".

So, do I have to restart something to get this to work, or is this not going to work the way I'm expecting?

I forgot about this question that I posted, and even posted a very similar question just a couple of months later: Need a working strategy to execute SQL scripts in Jenkins pipeline script .

I more thoroughly investigated this problem in the later posting, where I came to the conclusion that it's just not practical to execute Sql queries in "the Java way" inside the pipeline script. The only reasonable alternatives are directly executing the database command-line client ("sqlplus" or "mysql", for instance) and piping scripts into it, or writing tasks in a Gradle build script to execute the queries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM