1

使用 Scriptler 无法通过 Jenkins groovy 连接到 Postgresql,既不能通过执行 psql 命令,也不能通过使用 jdbc:

  1. psql
command = """
        PGPASSWORD=1111\
        psql -h xxxx.rds.amazonaws.com\
        -U master -d yyy -c "select * from table"
        """
proc =  command.execute()
proc.waitFor()
return proc.in.text 

我收到错误

无法运行程序“PGPASSWORD=1111”:错误=2,没有这样的文件或目录

  1. 数据库
import groovy.sql.Sql

def dbUrl      = "jdbc:postgresql://xxxx.rds.amazonaws.com/yyy"
def dbUser     = "master"
def dbPassword = "1111"
def dbDriver   = "org.postgresql.jdbcDriver"
def sql = Sql.newInstance(dbUrl, dbUser, dbPassword, dbDriver)

它返回

java.lang.ClassNotFoundException:org.postgresql.jdbcDriver

我安装了插件databasePostgreSQL API Plugin& database-postgresql。詹金斯 v.2.176.1

4

1 回答 1

0

因此,您通过 command.execute() 的第一次尝试将不起作用,因为您正在尝试使用 shell 命令语法并且您没有运行 shell。

第二个不起作用,因为您必须告诉 Groovy 在哪里可以找到 postgress jdbc 库。您也许可以使用 Groovy Grape 来做到这一点。

我个人会使用 shell 步骤执行 psql 命令。

于 2019-07-11T01:48:24.613 回答