Skip to content
Latchkey

How to Deploy to Firebase Hosting With Bitbucket Pipelines

Install firebase-tools, point GOOGLE_APPLICATION_CREDENTIALS at a service account key, and run firebase deploy --only hosting.

Firebase Hosting deploys with the firebase CLI. Use a service account key (preferred over a CI token, which is deprecated) by exporting GOOGLE_APPLICATION_CREDENTIALS, then deploy only the hosting target.

Steps

  • Create a service account with the Firebase Hosting Admin role and a JSON key.
  • Store the key (base64) as the secured variable FIREBASE_SA_KEY.
  • Export GOOGLE_APPLICATION_CREDENTIALS to the decoded key file.
  • firebase deploy --only hosting --project <id>.

Pipeline

bitbucket-pipelines.yml
image: node:20
pipelines:
  branches:
    main:
      - step:
          name: Deploy to Firebase Hosting
          deployment: production
          script:
            - npm ci && npm run build
            - npm i -g firebase-tools
            - echo "$FIREBASE_SA_KEY" | base64 -d > /tmp/fb-key.json
            - export GOOGLE_APPLICATION_CREDENTIALS=/tmp/fb-key.json
            - firebase deploy --only hosting --project "$FIREBASE_PROJECT" --non-interactive

Gotchas

  • The legacy FIREBASE_TOKEN / firebase login:ci flow is deprecated; use a service account.
  • Run the build before deploy so the public directory has the latest assets.
  • --non-interactive avoids the CLI hanging on a prompt in CI.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →