Postgresql 生成后在jenkins中运行postgres查询

Postgresql 生成后在jenkins中运行postgres查询,postgresql,jenkins,Postgresql,Jenkins,我在同一台centos7服务器上安装了jenkins和postgres 我还安装并配置了数据库和PostgreSQL数据库插件,如下图所示: 我想在我的数据库中插入数据,我想在构建成功后处理的表是构建,这样我就可以跟踪构建、部署等的历史 如何从jenkins运行对数据库的查询?使用postgresql命令创建一个脚本文件,比如build_complete.sh: #!/bin/bash #Updated command that solves the bug. Courtesy: Yousse

我在同一台centos7服务器上安装了jenkins和postgres

我还安装并配置了数据库和PostgreSQL数据库插件,如下图所示:

我想在我的数据库中插入数据,我想在构建成功后处理的表是构建,这样我就可以跟踪构建、部署等的历史


如何从jenkins运行对数据库的查询?

使用postgresql命令创建一个脚本文件,比如build_complete.sh:

#!/bin/bash

#Updated command that solves the bug. Courtesy: YoussefBoudaya's comment.
"export PGPASSWORD='postgres'; sudo -u postgres -H -- psql -d jenkinsdb -c "SELECT * FROM builds" postgres"
请确认来自服务器的psql路径,它将类似于/usr/lib/postgresql/10/bin/psql。 在管道末尾添加执行脚本步骤,然后简单地运行脚本


类似的解决方案也可以阅读。

当我在Jenkins build shell export PGPASSWORD='postgres'中运行此命令时/usr/bin/postgres-h172.16.4.26:5432:postgres-djenkinsdb-cselect*from builds。我遇到了致命的问题:-c从构建要求中选择*une valeur@YoussefBoudaya我已经更新了我的答案,以适应您使用的命令。您需要将端口和用户作为单独的变量添加。我解决了第一个问题,现在我遇到致命问题:-c Select*from builds requiret une valeur@YoussefBoudaya,一定是因为缺少分号。如果以结束命令,请告知我;解决问题?这是工作命令:export PGPASSWORD='postgres';sudo-u postgres-H-psql-d jenkinsdb-c从构建postgres中选择*