4

I do have a react.js app (create-react-app) I setup the file just like explained in the official docs, everything went good but the push failed with this specific line

git push https://heroku:$API_KEY@git.heroku.com/$APP_NAME.git HEAD:master

The bitbucket-pipelines.yml is on the root folder:

image: node:6
clone:
  depth: full
pipelines:
  default:
    - step:
        script:
          - npm install
          - npm test
          - git push git push https://heroku:$API_KEY@git.heroku.com/$APP_NAME.git HEAD:master

What I'm doing wrong? The goal here is to use the CI on bitbucket platform but also push master commits to heroku repository to automate deploys.

The error I'm getting is:

remote: !   WARNING:
remote: !   Do not authenticate with username and password using git.
remote: !   Run `heroku login` to update your credentials, then retry the git command.
remote: !   See documentation for details: https://devcenter.heroku.com/articles/git#http-git-authentication
fatal: Authentication failed for 'https://heroku
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

5

First, make sure your script does not involve git push git push https://heroku:.
It should be git push https://heroku:...

Second, as described here, make sure to use your HEROKU_API_KEY, the one returned by heroku authorizations --json (field "token")

image: node:6
clone:
  depth: full
pipelines:
  default:
    - step:
        script:
          - npm install
          - npm test
          - git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git HEAD:master
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • So in Bitbucket environment variables I should use same token? –  Oct 13 '18 at 07:32
  • @blvckasvp Yes, the same token as the one returned by `heroku authorizations --json`, in order for you to be correctly authenticated. – VonC Oct 13 '18 at 07:38
  • I believe I don't have to delete the dollar sign? –  Oct 13 '18 at 07:51
  • @blvckasvp If you have set the `HEROKU_API_KEY` variable, then `$HEROKU_API_KEY` will be correctly replaced by that value. – VonC Oct 13 '18 at 07:53
  • Alright it's working but got another issue, I make changes then push to bitbucket, using the pipelines it told me Updates were rejected because the remote contains work that you do: not have locally. I understand what it means it's just idk what I'm supposed to do –  Oct 13 '18 at 08:11
  • @blvckasvp Make sure your clone done by the pipeline is of the latest version of your remote repo: if they are new commits done on the repo, while your pipeline is trying to push its own, you would get that error message. – VonC Oct 13 '18 at 08:16
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/181801/discussion-between-blvckasvp-and-vonc). –  Oct 13 '18 at 08:25