Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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?

share|improve this question

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

share|improve this answer
    
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 – Maciej Sobala Jul 17 at 19:47
    
Then postgres is to blame. Here is a thread where they might have your solution: stackoverflow.com/questions/4480381/… – Gabriel Tigerström Jul 17 at 19:53
    
Works :) Thank you – Maciej Sobala Jul 17 at 19:57
up vote 0 down vote accepted

I changed my execution command to:

sudo -u postgres psql -v ON_ERROR_STOP=1 -d my_db < [path_to_file].sql
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.