Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you tell if running a command through the heroku cli succeeded?

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?

like image 669
Oved D Avatar asked Aug 05 '14 18:08

Oved D


1 Answers

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
like image 51
Taytay Avatar answered Oct 02 '22 05:10

Taytay