Search code examples
firebasetravis-cifirebase-hostingfirebase-cli

travis ci fails deploy on firebase hosting


I am trying to integrate travis ci on my firebase application to deploy automatically but it fails saying 401 error. Here is my .travis.yml

language: node_js
node_js:
 - '8'
deploy:
  provider: firebase
  token:
   secure: "BnzKtrzBaI/uLHoezYpBVqQ/VwhIyil...n0jAuBNrTI="
  message: build $TRAVIS_BUILD_NUMBER $TRAVIS_BRANCH/$COMMIT_HASH

and I get the following error:

Error: HTTP Error: 401, Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

I am not sure as what is going wrong.


Solution

  • I haven't used the provider function in Travis CI before, but another option of deploying to Firebase hosting is to install firebase-tools and use the CLI.

    language: node_js
    node_js: 8
    
    before_script:
      - npm install firebase-tools -g
    
    script:
      - firebase deploy --only hosting --token "BnzK...rTI="
    

    -- Edit: More information on Cloud Functions and Branch Filters. --

    If you're deploying Cloud Functions as well, you'll need to install the node_modules on travis before you can deploy.

    language: node_js
    node_js: 8
    
    before_script:
      - npm install firebase-tools -g
      - cd functions && npm install
    
    script:
      - firebase deploy --only hosting,functions --token "BnzK...rTI="
    

    If you want to only deploy when changes are made to the master branch you can add in this filter.

    language: node_js
    node_js: 8
    
    before_script:
      - npm install firebase-tools -g
      - cd functions && npm install
    
    script:
      - firebase deploy --only hosting,functions --token "BnzK...rTI="
    
    branches:
      only:
        - master