I am trying to execute postgres script using jenkis on remote server. Below are content of shell script. I am using publish over SSH plugin.
sudo -u postgres psql
CREATE USER sonar WITH PASSWORD 'sonar';
\du
CREATE DATABASE sonar WITH OWNER sonar encoding 'UTF8';
GRANT ALL PRIVILEGES ON DATABASE sonar TO sonar;
\l
\q
1) I can see contents are printed in terminal but not executed.
Solution I tried:
I created my scripts like
#!/bin/bash
sudo -h myip -u postgres bash -c "psql -c \"CREATE USER sonar WITH PASSWORD 'sonar';\""
sudo -h myip -u postgres bash -c "psql -c \"CREATE DATABASE sonar WITH
OWNER sonar encoding 'UTF8';\""
sudo -h myip -u postgres bash -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE sonar TO sonar;\""
This script is working fine but I have to connect remote server multiple times. I want script to connect once and execute all psql queries.
2) I am also looking for dev and staging environment executed 1st and then production. Can we manage Plugin in this way?