Joan Martín
Joan Martín

Reputation: 129

Travis doesn't deploy on heroku. Invalid credentials

I'm trying to set up automatic deploy on heroku with travis. I get this error when travis try to deploy:

API request failed.

Message: Invalid credentials provided.

Reference: 

failed to deploy

This is my travis file:

jobs:
  include:
    - language: python
      python:
        - "3.6"    
      install:
        - pip install -r Deployment/requirements.txt
      script:
        - python -c "print ('Testing some script')"
      branches:
      only:
      - master
      - develop
      before_deploy:
        - cd Deployment
      deploy:
        - provider: heroku
          skip_cleanup: true
          api_key:
            secure: b3AVdCtJ2e/+Gu1...
          app:
            master: motorent-deploy
            develop: motorent-apitest

    - language: android
      dist: trusty
      env:
        global:
          - ANDROID_API_LEVEL=29
          - ANDROID_BUILD_TOOLS_VERSION=29.0.3
          - extra-google-google_play_services
          - extra-google-m2repository
          - extra-android-m2repository
          - addon-google_apis-google-$ANDROID_API_LEVEL
      android:
        licenses:
          - 'android-sdk-preview-license-.+'
          - 'android-sdk-license-.+'
          - 'google-gdk-license-.+'
        components:
          - tools
          - platform-tools
          - android-$ANDROID_API_LEVEL
          - build-tools-$ANDROID_BUILD_TOOLS_VERSION
          - extra-google-google_play_services
          - extra-google-m2repository
          - extra-android-m2repository
          - addon-google_apis-google-$ANDROID_API_LEVEL
      addons:
        apt:
          packages:
            ant
      before_install:
          - touch $HOME/.android/repositories.cfg
          - yes | sdkmanager "platforms;android-29"
          - yes | sdkmanager "build-tools;29.0.3"
      before_script:
        - cd AndroidApp
        - chmod +x gradlew
      script:
        - ./gradlew build check 

As you can see I have two differents projects in the same repository, but it's not important, because the android test works well. What doesn't work is the deploy of Flask project. The solutions that I have found talk about the need to encrypt the api_key. I have tested it with Travis encrypt $(heroku auth:token) but it doesn't work either.

I've been trying to find the error for a long time but I don't know what it can be.

Upvotes: 1

Views: 362

Answers (1)

Piotr Kowalski
Piotr Kowalski

Reputation: 551

I had the same error.

Here are steps that I performed to fix it.

Firstly I tried the command: heroku auth:token but the output was:

 ›   Warning: token will expire 06/06/2021
 ›   Use heroku authorizations:create to generate a long-term token

Then I tried the command: heroku authorizations:create

One line from the output contained Token: <created_heroku_auth_token>

I took the value of it (<created_heroku_auth_token>) and I went to

https://travis-ci.org/github/<my_github_user>/<my_repo>/settings

where I created new environment variable:

HEROKU_AUTH_TOKEN with value of my <created_heroku_auth_token>

Then in my .travis.yml I changed value of api_key to:

api_key: $HEROKU_AUTH_TOKEN

After pushing this change, the deployment to heroku went fine.

Upvotes: 1

Related Questions