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

2

10

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?

Obedient answered 5/8, 2014 at 18:59 Comment(0)
X
10

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
Xanthus answered 28/8, 2015 at 7:32 Comment(0)
G
0

You're not alone with this. Many have complained about this before, check this out:
https://github.com/heroku/heroku/issues/186

You can (dirty) work around the problem with this gem:
https://github.com/glenngillen/heroku-exit-status

Gait answered 30/9, 2014 at 9:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.