jenkins连接posgreSQL数据库
需要安装插件:
PostgreSQL Database
然后在global configuration配置数据库连接信息
mytests表存放json数据
import groovy.json.JsonSlurper
#Pipeline example: pipeline { agent any stages { stage('# 构建开始') { steps { script{ getDatabaseConnection(type: 'GLOBAL') { def result = sql(sql: "select info from mytests;")
println "Class of result: ${result.getClass().toString()}" println "Value of result: ${result}"
req_str = result[0]["info"].getValue()
def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parseText(req_str)
println(object["build_type"])
} } } } } }
连接数据库语法:https://www.jenkins.io/doc/pipeline/steps/database/
https://www.cnblogs.com/k4nz/p/14577301.html