Heroku command requires login



Hi Community,

I am having trouble deploying a Rails4 app to Heroku with CircleCI.
Specifically, I get this in the deployment step.

$ heroku run rake db:migrate --app <APP_NAME>
Enter your Heroku credentials.
command heroku run rake db:migrate --app <APP_NAME> took more than 400 seconds since last output

My circle.yml is like that:

    - echo "test"
    branch: <BRANCH_NAME>
      - "[[ ! -s \"$(git rev-parse --git-dir)/shallow\" ]] || git fetch --unshallow"
      - git push git@heroku.com:<APP_NAME>.git $CIRCLE_SHA1:refs/heads/master
      - heroku run rake db:migrate --app  <APP_NAME>:
          timeout: 400

and the last line fails.

I confirmed the project’s Heroku API Key and Current deploy user are correctly set to those of my heroku account.
Also, when I tried Rebuild with SSH, I logged in the CircleCI container and successfully executed heroku run.. itself, although I needed to login.
Any Ideas on what config else to check?

I checked other steps on CircleCI.

  • Install Heroku API credentials step shows nothing but it is green, so I think it was successful.
  • $ git push git@heroku.com:.. step shows the result like this, so I think it was also successful.
git push git@heroku.com:<APP_NAME>.git $CIRCLE_SHA1:refs/heads/master
Warning: Permanently added 'heroku.com,50.19.XX.XXX' (RSA) to the list of known hosts.

Everything up-to-date



me too, I don’t know how to login.

maybe you can try this : “Heroku with pre- or post-deployment steps” on https://circleci.com/docs/1.0/continuous-deployment-with-heroku/
But for me it was not working either



There was a pending pull request for that page to fix that information. It is now updated, https://circleci.com/docs/1.0/continuous-deployment-with-heroku/#pre-or-post.

Basically, when you do manual Heroku deployments, the creds from the UI aren’t read and you need to set them as environment variables instead.


@satzz @nicolasmlv Please let us know if you’re still having trouble with Heroku deploy.


I think there is a typo in the doc : “password $HEROKU_TOKEN” should be “password $HEROKU_PASSWORD” ?

Maybe you should add this “Add HEROKU_LOGIN and HEROKU_PASSWORD in your project > Build Settings > Environment variables” I did not find it quickly where was those build var

But no, it is not working, it still says “Enter your Heroku credentials.” when there is the step “heroku run rails db:migrate”, although I set HEROKU_EMAIL and HEROKU_PASSWORD build vars


There was a typo but it’s the other way around: https://github.com/circleci/circleci-docs/pull/627

As long as you match the variable names you set in the UI with the variable names in circle.yml, you’re good. Is it possible for you to paste the deployment section of your circle.yml?


I fixed my circle.yml:

        branch: circleci
          - |
            cat >~/.netrc <<EOF
            machine api.heroku.com
              login $HEROKU_EMAIL
              password $HEROKU_TOKEN
            machine git.heroku.com
              login $HEROKU_EMAIL
              password $HEROKU_TOKEN
          - chmod 600 ~/.netrc
          - "[[ ! -s \"$(git rev-parse --git-dir)/shallow\" ]] || git fetch --unshallow"
          - git push git@heroku.com:XXXX.git $CIRCLE_SHA1:refs/heads/master
          - heroku run rake db:migrate --app XXXX:
              timeout: 400

And I still get this in the last action:

heroku run rake db:migrate --app XXXX
 !    Error reading /home/ubuntu/.netrc
 !    unexpected EOF
 !    You may need to delete this file and run `heroku login` to recreate it.

heroku run rake db:migrate --app XXXX returned exit code 1

Action failed: heroku run rake db:migrate --app XXXX


Do you mean I need to set HEROKU_EMAIL and HEROKU_TOKEN as below?


Yes, that needs to be set in the UI before the variables will be available within your build.


I retried but the result didn’t change.
Here’s all that I did:

  • set Heroku API key on CircleCI account
  • set a deploy user on CircleCI project
  • add a new private key to SSH Permissions on CircleCI project
  • encrypt secret-env-plain into secret-env-cipher with openssl with the same key
  • push secret-env-cipher to the Bitbucket and run the CircleCI build

Do I need to add openssl aes-256-cbc -d -in secret-env-cipher -k $KEY >> ~/.circlerc to circle.yml? How can I define $KEY without including the actual key in the repo?


Hi, I had been trying Bitbucket private repo, but switching to Github private repo with this simple yml worked:

    - echo "testing"
    branch: circleci
      - git push git@heroku.com:XXX.git $CIRCLE_SHA1:master
      - heroku run rake db:migrate --app XXX

I don’t understand why, but this might be one solution. Thanks!