When running a command through heroku, such as:
heroku run rake db:migrate
I would like to know if the command succeeded or not. Unfortunately, even if running the migration fails, I get an exit status of 0.
I'm writing some ruby code that wraps this command and invokes it, and raises an error if the command failed. The code looks like:
Open3.popen2e('heroku run rake db:migrate') do |stdin, stdout_and_stderr, wait_thr|
raise 'running migration failed' unless wait_thr.value.success?
end
Even when running this fails, and I get a message:
rake aborted! StandardError: An error has occurred, this and all later migrations canceled:
My code itself does not raise an error. Inspecting wait_thr.value in the above code, it has an exit code of 0, which means the heroku CLI believes the rake call succeeded.
How can my code know if the command that was run by the heroku cli failed? Is there a way to tell the heroku CLI to return the status code of the command it ran?
There is now official support for this from their CLI:
heroku help run
Usage: heroku run COMMAND
run an attached dyno
-s, --size SIZE # specify dyno size
--exit-code # return exit code from process
So you would now run:
heroku run --exit-code rake db:migrate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With