1

I got my database dump (tables, functions, triggers etc) in *.sql files. At this moment I am deploying them via jenkins, by passing execute shell command:

sudo -u postgres psql -d my_db < /[path_to_my_file].sql

The problem is, that if something is wrong in my sql file, build finishes as SUCCESS. I would like to got information immediately if something fails, without looking into log and checking if every command executed succesfully.

Is it possible (and how if the answer is 'yes') to deploy postgres database via jenkins other way?

2 Answers 2

1

I changed my execution command to:

sudo -u postgres psql -v ON_ERROR_STOP=1 -d my_db < [path_to_file].sql
Sign up to request clarification or add additional context in comments.

Comments

1

Make sure you have set set -e Before running the command. If that does not work, I'd look at the return code from the command above. That can be done by running echo $? right after the command.

If that gives you a zero when it fails it's postgres fault (sice it should return with something else than 0 on fail).

Perhaps there is a postgres flag to fail on wrong input.

EDIT: -v ON_ERROR_STOP=1 As a flag to postgres should make postgres fail on errors

3 Comments

Both solutions doesn't work: ERROR: insert or update on table "quantity_audit" violates foreign key constraint "quantity_audit_product_id_fkey" DETAIL: Key (product_id)=(5) is not present in table "products". INSERT 0 1 + echo 0 0 Finished: SUCCESS
Then postgres is to blame. Here is a thread where they might have your solution: stackoverflow.com/questions/4480381/…
Works :) Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.