在jenkins管道groovy脚本中的oracle数据源未知源

时间:2016-08-15 07:41:58

标签: oracle jenkins groovy jenkins-pipeline

我正在尝试使用groovy从jenkins中的管道脚本执行sql查询, 但它无法解析oracle数据源(oracle.jdbc.pool.OracleDataSource)。请让我知道如何才能完成这项工作。

import groovy.sql.Sql

    def parent = getClass().getClassLoader()
    def loader = new GroovyClassLoader(parent)

   def ConfigEntityObj
   def ServiceEntityObj   
   def DBConnClassObj
   def TibcoServiceXMLClassObj
   String driverName = "oracle.jdbc.pool.OracleDataSource";
   Class.forName(driverName);

    ConfigEntityObj = loader.parseClass(new File("D://Pedda//Tibco_Automation//src//com//merck//Entity//ConfigEntity.java")).newInstance()
    ServiceEntityObj = loader.parseClass(new File("D://Pedda//Tibco_Automation//src//com//merck//Entity//ServiceEntity.java")).newInstance()    
    DBConnClassObj = loader.parseClass(new File("D://Pedda//Tibco_Automation//src//com//merck//comet//DBConnectionManager.groovy")).newInstance()
    TibcoServiceXMLClassObj = loader.parseClass(new File("D://Pedda//Tibco_Automation//src//com//merck//comet//TibcoServiceXML.groovy")).newInstance()

    TibcoServiceXMLClassObj.callSQL()



public void callSQL() {

    try {

        def sql = Sql.newInstance('jdbc:oracle:thin:@DS-3860778D2AF5:1521:xe', 'tibco_automation', 'tibco_automation', 'oracle.jdbc.pool.OracleDataSource')

        sql.query('select * from ISS_APPS_INVENTORY') { resultSet ->
            while (resultSet.next()) {
                println "hi"
                println resultSet.getString(1)
            }

            File file1 = new File("D://Pedda//ResultSet.txt");
            file1.write(resultSet.getString(1))


        }

    }catch(Exception e){
      e.printStackTrace()
        File file = new File("D://Pedda//SQL.txt");
        file.write(e.getMessage()+ " Exception "+e.getStackTrace())

    }
}

以下例外情况。

oracle.jdbc.pool.OracleDataSourceException [java.net.URLClassLoader.findClass(Unknown Source), 
java.lang.ClassLoader.loadClass(Unknown Source), 
java.lang.ClassLoader.loadClass(Unknown Source), 
org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:450), 
org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:403), 
java.lang.Class.forName0(Native Method), 
java.lang.Class.forName(Unknown Source), groovy.sql.Sql.loadDriver(Sql.java:705), 
groovy.sql.Sql.newInstance(Sql.java:445), 
groovy.sql.Sql$newInstance.call(Unknown Source), 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48), 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113), 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149), 
com.merck.comet.DBConnectionManager.getServiceList(DBConnectionManager.groovy:84), 
com.merck.comet.DBConnectionManager$getServiceList$0.call(Unknown Source), 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48), 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113), 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125), 
com.merck.comet.TibcoServiceXML.createServiceXML(TibcoServiceXML.groovy:34), 
com.merck.comet.TibcoServiceXML$createServiceXML.call(Unknown Source), 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48), 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113), 
com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:15), 
com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:55), 
com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:106), 
com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:74), 
sun.reflect.GeneratedMethodAccessor692.invoke(Unknown Source), 
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source), 
java.lang.reflect.Method.invoke(Unknown Source), 
com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72), 
com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21), 
com.cloudbees.groovy.cps.Next.step(Next.java:58), 
com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154), 
org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:164), 
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:297), 
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$000(CpsThreadGroup.java:78), 
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:206), 
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:204), 
org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:47), 
java.util.concurrent.FutureTask.run(Unknown Source), 
hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112), 
jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28), 
java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source), 
java.util.concurrent.FutureTask.run(Unknown Source), 
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source), 
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source), 
java.lang.Thread.run(Unknown Source)]

1 个答案:

答案 0 :(得分:1)

再一次是在适当的位置添加jar的情况,在我的本地,Jenkins是独立运行的。在服务器中它运行在Tomcat中,所以我不得不在Jenkins-> Apache-tomcat-> bin中添加jar文件。