# Heroku command requires login

**URL:** <https://discuss.circleci.com/t/heroku-command-requires-login/7996>\
**Category:** Deployments\
**Tags:** heroku\
**Created:** [November 8, 2016, 7:37pm UTC](https://discuss.circleci.com/t/heroku-command-requires-login/7996 "2016-11-08T19:37:25Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![satzz](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/satzz/32/5216_2.png) [@satzz](https://discuss.circleci.com/u/satzz)\
**Post date:** [November 8, 2016, 7:37pm UTC](https://discuss.circleci.com/t/heroku-command-requires-login/7996/1 "2016-11-08T19:37:26Z")

</div>

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.
Email: 
command heroku run rake db:migrate --app <APP_NAME> took more than 400 seconds since last output

```

My circle.yml is like that:

```
test:
  override:
    - echo "test"
deployment:
  staging:
    branch: <BRANCH_NAME>
    commands:
      - "[[! -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?

ADDED:  
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.

```auto
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

```

Thanks!

---

<div class="post-metadata">

**Author:** ![nicolasmlv](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/nicolasmlv/32/15416_2.png) [@nicolasmlv](https://discuss.circleci.com/u/nicolasmlv)\
**Post date:** [February 8, 2017, 3:11pm UTC](https://discuss.circleci.com/t/heroku-command-requires-login/7996/2 "2017-02-08T15:11:36Z")

</div>

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/](https://circleci.com/docs/1.0/continuous-deployment-with-heroku/)  
But for me it was not working either

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [February 8, 2017, 3:37pm UTC](https://discuss.circleci.com/t/heroku-command-requires-login/7996/3 "2017-02-08T15:37:05Z")

</div>

Hi,

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](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.

---

<div class="post-metadata">

**Author:** ![zzak](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/zzak/32/4233_2.png) [@zzak](https://discuss.circleci.com/u/zzak)\
**Post date:** [February 10, 2017, 4:55am UTC](https://discuss.circleci.com/t/heroku-command-requires-login/7996/4 "2017-02-10T04:55:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nicolasmlv](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/nicolasmlv/32/15416_2.png) [@nicolasmlv](https://discuss.circleci.com/u/nicolasmlv)\
**Post date:** [February 10, 2017, 11:14am UTC](https://discuss.circleci.com/t/heroku-command-requires-login/7996/5 "2017-02-10T11:14:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [February 10, 2017, 8:31pm UTC](https://discuss.circleci.com/t/heroku-command-requires-login/7996/6 "2017-02-10T20:31:35Z")

</div>

There was a typo but it’s the other way around: [https://github.com/circleci/circleci-docs/pull/627](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`?

---

<div class="post-metadata">

**Author:** ![satzz](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/satzz/32/5216_2.png) [@satzz](https://discuss.circleci.com/u/satzz)\
**Post date:** [February 11, 2017, 4:25am UTC](https://discuss.circleci.com/t/heroku-command-requires-login/7996/7 "2017-02-11T04:25:43Z")

</div>

I fixed my `circle.yml`:

```
  deployment:
      staging:
        branch: circleci
        commands:
          - |
            cat >~/.netrc <<EOF
            machine api.heroku.com
              login $HEROKU_EMAIL
              password $HEROKU_TOKEN
            machine git.heroku.com
              login $HEROKU_EMAIL
              password $HEROKU_TOKEN
            EOF
          - 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
```

---

<div class="post-metadata">

**Author:** ![satzz](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/satzz/32/5216_2.png) [@satzz](https://discuss.circleci.com/u/satzz)\
**Post date:** [February 11, 2017, 4:32am UTC](https://discuss.circleci.com/t/heroku-command-requires-login/7996/8 "2017-02-11T04:32:54Z")

</div>

Do you mean I need to set HEROKU\_EMAIL and HEROKU\_TOKEN as below?

- [https://circleci.com/docs/1.0/environment-variables/#keeping-encrypted-environment-variables-in-source-code](https://circleci.com/docs/1.0/environment-variables/#keeping-encrypted-environment-variables-in-source-code)

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [February 11, 2017, 4:45am UTC](https://discuss.circleci.com/t/heroku-command-requires-login/7996/9 "2017-02-11T04:45:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![satzz](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/satzz/32/5216_2.png) [@satzz](https://discuss.circleci.com/u/satzz)\
**Post date:** [February 14, 2017, 3:58pm UTC](https://discuss.circleci.com/t/heroku-command-requires-login/7996/10 "2017-02-14T15:58:05Z")

</div>

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

```auto
HEROKU_TOKEN=...
HEROKU_EMAIL=...

```

- 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?

---

<div class="post-metadata">

**Author:** ![satzz](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/satzz/32/5216_2.png) [@satzz](https://discuss.circleci.com/u/satzz)\
**Post date:** [March 5, 2017, 3:29pm UTC](https://discuss.circleci.com/t/heroku-command-requires-login/7996/11 "2017-03-05T15:29:25Z")

</div>

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

```auto
test:
  override:
    - echo "testing"
deployment:
  staging:
    branch: circleci
    commands:
      - 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!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:41am UTC](https://discuss.circleci.com/t/heroku-command-requires-login/7996/12 "2018-06-18T11:41:08Z")

</div>

Closed on June 18, 2018, 11:41am UTC


